## 求正则（只能是以字母或者字母加数字 不能纯数字 5-15个字符）

Luffy666 发布于 2013/08/13 14:51

0

([a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*){5,15}

0
`/[a-z\d]+[a-z][a-z\d]+/gi`

上面这个可以验证格式，就是不能验证长度。

0

0

^[a-zA-Z]\w{5,15}\$

0

#### 引用来自“purejava”的答案

([a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*){5,15}

0
\w[\w\d]{4,14}
0
m

`/(?!\d+\$)[\dA-Za-z]{5,15}/.test(s)`

0

#### 引用来自“purejava”的答案

([a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*){5,15}

```Pattern pattern = Pattern.compile("([a-zA-Z0-9]*)([a-zA-Z])([a-zA-Z0-9]*)");
String[] strs = { "abcd8", "a8888", "8abcd", "8888a", "88a88", "ab8cd", "abcde", "88888" };
for (String str : strs) {
Matcher matcher = pattern.matcher(str);
if (matcher.find()) {
System.out.println(str + " : " + matcher.group(1) + " " + matcher.group(2) + " " + matcher.group(3));
} else {
System.out.println(str + " : No match");
}
}```

```abcd8 : abc d 8
a8888 :  a 8888
8abcd : 8abc d
8888a : 8888 a
88a88 : 88 a 88
ab8cd : ab8c d
abcde : abcd e
88888 : No match```

0

#### 引用来自“purejava”的答案

([a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*){5,15}

```Pattern pattern = Pattern.compile("([a-zA-Z0-9]*)([a-zA-Z])([a-zA-Z0-9]*)");
String[] strs = { "abcd8", "a8888", "8abcd", "8888a", "88a88", "ab8cd", "abcde", "88888" };
for (String str : strs) {
Matcher matcher = pattern.matcher(str);
if (matcher.find()) {
System.out.println(str + " : " + matcher.group(1) + " " + matcher.group(2) + " " + matcher.group(3));
} else {
System.out.println(str + " : No match");
}
}```

```abcd8 : abc d 8
a8888 :  a 8888
8abcd : 8abc d
8888a : 8888 a
88a88 : 88 a 88
ab8cd : ab8c d
abcde : abcd e
88888 : No match```

0

#### 引用来自“purejava”的答案

([a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*){5,15}

```Pattern pattern = Pattern.compile("([a-zA-Z0-9]*)([a-zA-Z])([a-zA-Z0-9]*)");
String[] strs = { "abcd8", "a8888", "8abcd", "8888a", "88a88", "ab8cd", "abcde", "88888" };
for (String str : strs) {
Matcher matcher = pattern.matcher(str);
if (matcher.find()) {
System.out.println(str + " : " + matcher.group(1) + " " + matcher.group(2) + " " + matcher.group(3));
} else {
System.out.println(str + " : No match");
}
}```

```abcd8 : abc d 8
a8888 :  a 8888
8abcd : 8abc d
8888a : 8888 a
88a88 : 88 a 88
ab8cd : ab8c d
abcde : abcd e
88888 : No match```

`select * from person where name like '%小%'`