D
D
Drovosek012021-10-06 15:25:33
JavaScript
Drovosek01, 2021-10-06 15:25:33

Why does JS match backtick in regular expression?

Good day.

There is the following regular expression:
/^[A-Yaa-yaёЁ]+[A-Yaa-yaёЁ\s\-'\d]+[A-Yaa-yaёЁ\-'\d]$/i

When checking it in the devtools console (Google Chrome) - "matches" a string with a reverse apostrophe (which is on the key with the letter "ё")

615d954df3a1f871541183.jpeg

Here is the code:

let str = 'тест`ТЕСТ 123-45-54 654'

let regexp = /^[A-Яа-яёЁ]+[A-Яа-яёЁ\s\-'\d]+[A-Яа-яёЁ\-'\d]$/i

str.match(regexp)


In sites-"sandboxes" for checking regular seasons, everything is fine, this line does not match.

Why does JS give a match to the specified string if the backtick character is not specified in the regular expression? How to fix this behavior?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexandroppolus, 2021-10-06
@Drovosek01

[A-Z]
here the letter A is Latin, in the interval between Latin A and Russian I there are a lot of things. Check the letters.

A
Anton Anton, 2021-10-06
@Fragster

Some kind of crap when using the range of capital letters A-Z in the list of characters. If it is not specified (and it does not need to be specified - after all, the i flag is specified), then everything works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question