This question already has an answer here:
这个问题已经有了答案:
- Difference between regex [A-z] and [a-zA-Z] 6 answers
- regex [A-z]和[a-zA-Z] 6答案的区别。
I'm struggling with the following regexp
我正在和下面的regexp斗争。
[A-z0-9]+
If tested against this string:
如果对该字符串进行测试:
||a919238[.--a]asd|
it returns a919238[
, including the square bracket.. I tried to input my test case on regex101 to understand what's wrong, but the site regex explanation is not helping, probably I'm not able to see my mistake.
它返回a919238[,包括方括号。我试着在regex101上输入我的测试用例来理解什么是错误的,但是网站regex解释没有帮助,很可能我不能看到我的错误。
Why is the square bracket included in the result?
为什么结果中包含方括号?
3 个解决方案
#1
112
Because
因为
[A-z0-9]+
↑ ↑
is from A
to z
, see the ASCII table, ]
appears between the two characters:
从A到z,看ASCII表,]出现在两个字符之间:
#2
19
A===>64
z===>122
[===>91
So it is in between the range you have defined.Use [A-Za-z0-9]+
它在你定义的范围之间。使用[A-Za-z0-9]+
#3
8
You can use /[a-z0-9]+/i
(the i
makes it case-insensitive), or /[A-Za-z0-9]+/
.
您可以使用/[a-z0-9]+/i(我使它不区分大小写),或/[A-Za-z0-9]+/。
#1
112
Because
因为
[A-z0-9]+
↑ ↑
is from A
to z
, see the ASCII table, ]
appears between the two characters:
从A到z,看ASCII表,]出现在两个字符之间:
#2
19
A===>64
z===>122
[===>91
So it is in between the range you have defined.Use [A-Za-z0-9]+
它在你定义的范围之间。使用[A-Za-z0-9]+
#3
8
You can use /[a-z0-9]+/i
(the i
makes it case-insensitive), or /[A-Za-z0-9]+/
.
您可以使用/[a-z0-9]+/i(我使它不区分大小写),或/[A-Za-z0-9]+/。