What is the difference between two regex patterns

I tried to check the company name in the web application and had this regex pattern

^[a-zA-Z_'\\s,;.-0-9]{1,100}$

The above pattern will reject the value 10004 Estates Limited

But if I push 0-9, then the pattern becomes

^[a-zA-Z0-9_'\\s,;.-]{1,100}$

then it works. I am new to regex and patterns, but I know that I have to use it more, so I want to be extremely clear. Thank.

+3
source share
2 answers

-is a special character in character classes and, therefore, is .-0-9ambiguous and probably gets the value .before 0and -and 9, therefore, essentially characters ./09-.

- , , ( , , ).

: , , , .NET regex engine:

PS> [char[]](32..127) -match '[a-zA-Z_''\s,;.-0-9]'

'
,
-
.
/
0
9
;
A
...
+7

, - "-"

^[a-zA-Z_'\s,;.\-0-9]{1,100}$

Escaspe, .

, , ,

backslash \
caret ^
hyphen -
+2

All Articles