Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript RegExp not working in IE11 and working in Chrome [duplicate]

I have created the following RegExp object:

RegExp(/_if|_elseif|_else|_while|_store/, "g")

I need to match either of the pipe delim strings. The above method works in chrome. But the IE11 throws error saying some syntax error.

like image 490
Shyam R Avatar asked Jan 18 '26 15:01

Shyam R


1 Answers

That's because the RegExp constructor in IE11 only takes a string as its first argument, and not a regular expression literal:

RegExp("_if|_elseif|_else|_while|_store", "g")
       ^                               ^

Alternatively, you can simply add the g flag to the end of your regular expression literal and drop the constructor notation altogether:

/_if|_elseif|_else|_while|_store/g
like image 128
James Donnelly Avatar answered Jan 20 '26 04:01

James Donnelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!