0

I have a regex which finds any string between 2 ##-characters:

var regex = new RegExp('(?<=\#\#)(.*?)(?=\#\#)');
var matchResult = searchString.match(regex);

E.g. a string

"test bla bla ##TARGET## blablabla" gives me TARGET, which is what I want. It is working fine in Chrome and Firefox. However MS Edge gives me the error message:

Unexpected quantifier

How do I need to change the regex, that it also works for Microsoft Edge? I tried escaping the ? but that did not help. Which characters do I need to escape?

Michael B
  • 1,660
  • 3
  • 28
  • 59
  • 1
    Edge doesn't support lookbehinds, – revo Jul 06 '18 at 10:26
  • 1
    `var matchResult = searchString.match(/##(.*?)##/)[1];`. Matching a string between two strings with JavaScript regex is a very common issue and has been covered in many SO (and other) posts. A lookbehind is supported by ECMAScript 2018 compatible JS environments only. – Wiktor Stribiżew Jul 06 '18 at 10:26
  • Have you tried double escaping the hash symbols? Older IE had issues with this, not sure how it is now. `new RegExp('(?<=\\#\\#)(.*?)(?=\\#\\#)');` – Dropout Jul 06 '18 at 10:40

0 Answers0