[A-z0-9]+ regexp matching square brackets

Regex

Regex 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:

enter image description here

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]+/.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBeNdErRView Question on Stackoverflow
Solution 1 - RegexMarounView Answer on Stackoverflow
Solution 2 - RegexvksView Answer on Stackoverflow
Solution 3 - RegexAhosan Karim AsikView Answer on Stackoverflow