Skip to content

‘unexpected quantifier’ regexp error in IE11

I have a strings like SHM{GHT} and need to get a value from brackets (GHT in this example). I use RegExp to get it and everything worked fine before I open it in IE. My page broke here and I got an error unexpected quantifier.

Here is my function

const getValueFromBrackets = (el): string => {
  const valueFromBrackets = el.match(/(?<={).+?(?=})/g);
  return valueFromBrackets[0];

I checked on CanIUse .match() should work fine, something wrong with inside part /(?<={).+?(?=})/g. Any idea how can I rewrite it?

Would be really grateful for help!


The problem is with the lookbehind assertion <={, which is not supported in old engines. As a workaround, match {(...)} and take the first group: