Why is this JavaScript Regex matching underscore?

I am trying to use the following JavaScript RE to match a string where valid characters are uppercase or lowercase letters, numbers, hypens (-) and periods (.). Underscore "_" is not allowed:

pattern = /^([a-zA-z0-9\-\.]+)$/

But when I run the test on the Chrome console: pattern.test ("_ Linux");

The result is correct, but must be false in accordance with our rules. What reason?

+4
source share
1 answer

A-z ( z ). JavaScript regex 65 122, 65 90. (char 95); . ASCII. Z, :

^([a-zA-Z0-9\-\.]+)$
+9

Source: https://habr.com/ru/post/1650977/


All Articles