[A-z0-9]+ regexp matching square brackets
RegexRegex Problem Overview
I'm struggling with the following 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.
Why is the square bracket included in the result?
Regex Solutions
Solution 1 - Regex
Because
[A-z0-9]+
↑ ↑
is from A
to z
, see the ASCII table, ]
appears between the two characters:
Solution 2 - Regex
A===>64
z===>122
[===>91
So it is in between the range you have defined.Use [A-Za-z0-9]+
Solution 3 - Regex
You can use /[a-z0-9]+/i
(the i
makes it case-insensitive), or /[A-Za-z0-9]+/
.