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!
Advertisement
Answer
The problem is with the lookbehind assertion <={
, which is not supported in old engines. As a workaround, match {(...)}
and take the first group:
console.log('SHM{GHT}'.match(/{(.+)}/)[1])