Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does [\W_]+ with i modifier in Javascript regex match i,k,s?

Forgot to remove the i modifier in a pattern, that should strip out non alphanumeric characters:

str.replace(/[\W_]+/gi," ");

And wondered, that [\W_] will match i,k and with + quantifier even s :D

Without the i modifier it's working fine. And of course the i modifier is a mistake, but I don't understand this weird behavior: regex101 and here is a fiddle

I'm using Firefox 32.0.1

enter image description hereenter image description here

like image 733
Jonny 5 Avatar asked Sep 14 '14 18:09

Jonny 5


1 Answers

It's a bug that affects Firefox 32.0 and 32.0.1.

It has already been fixed on Firefox 33 Beta.

like image 75
Oriol Avatar answered Oct 17 '22 13:10

Oriol