1

the following javascript line is throwing error with the message only on IE:

SyntaxError: Unexpected Identifier

var result = new RegExp('(?<=\"compliantNotes\": \").*(?=\"\s+\"compliantDetected\":)', 'sgmi').exec(inputString);

I created a working copy here: RegExp Online

The regular expression seems to work fine on Chrome, returning the expected result but I can't figure out why that throws error in IE 11.

Thank you

Raptor
  • 53,206
  • 45
  • 230
  • 366
IMR
  • 959
  • 6
  • 8
  • 4
    Look-behind assertions are not supported in IE, Firefox and many other browsers. Check the browser compatibility in [this table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Browser_compatibility). – 31piy Aug 14 '18 at 04:05
  • Thank you @31piy I didn't notice it.. that explains the issue. Is there an alternative way to achieve the same result? – IMR Aug 14 '18 at 04:08
  • 1
    @31piy I thought it's only *negative* lookbehind that isn't supported in Javascript. – Barmar Aug 14 '18 at 04:09
  • The google search yielded [this post](https://stackoverflow.com/questions/7376238/javascript-regex-look-behind-alternative) as the first result. You should research more, and if it doesn't solve your problem, you should refactor your code or use a different approach altogether. – 31piy Aug 14 '18 at 04:09
  • @Barmar -- I was not sure of either, so I referenced the MDN docs first, and it reported the compatibility status as _unknown_. – 31piy Aug 14 '18 at 04:10
  • Thanks @31piy I found that just now. I will do some more research/refactor my code. Question is, why on the website "regex101.com" that same regexp works in IE? – IMR Aug 14 '18 at 04:11
  • 1
    If you switch to **JavaScript** on regex101 using IE/Edge/Firefox it's not working. – wp78de Aug 14 '18 at 04:52
  • thanks guys, all clear – IMR Aug 14 '18 at 21:46

0 Answers0