Hello. Why regular season

var rep = /[^\*a-zA-Zа-яёА-ЯЁ0-9_-]/g; 

It works as it should, and regular

 var rep = /[^a-zA-Zа-яёА-ЯЁ0-9_-\*]/g; 

Gives an error range out of order in character class? Same thing in php.

  • 3
    because a dash denotes a range of character class, and the character class _-* does not exist. - etki

1 answer 1

Because the "-" indicates that a range of characters is used.
Accordingly, this design

 _-\* 

interpreted as follows: select characters from "_" to "*"

Naturally, there is no definition of such a range, so an error is generated.

The "-" symbol is indicated at the end of the listing in order not to have to screen it.
For your case, the correct entry would be:

 var rep = /[^a-zA-Zа-яёА-ЯЁ0-9_\-\*]/g; 
  • that is, without knowing it, did the right thing. Until I wanted to add an asterisk. Thank. - sinedsem