Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript Unexpected Quantifier Error in Internet Explorer, but works in Google Chrome

The following code snippet is causing Internet Explorer to throw an Unexpected Quantifier error, but Google chrome is working just fine.

var regexWord = new RegExp("\\b(?<!-)"+lWord+"\\b(?!-)");

How to fix this so it works cross browser?

UPDATE

After some testing it appears the error is a result of (?<!-) in the regex pattern. Though, still not sure how to fix it. Seems like it is correct based on the regex documentations I've read.

like image 620
Ron Ross Avatar asked Feb 08 '18 01:02

Ron Ross


1 Answers

Only Google Chrome supports lookbehind ?<!

So replacing (?<!-) with [^-] should do the trick.

like image 105
Kosh Avatar answered Oct 16 '22 12:10

Kosh