slevithan / xregexp

Extended JavaScript regular expressions
http://xregexp.com/
MIT License
3.31k stars 278 forks source link

xregexp and recursion or balancing groups support #270

Closed tdjastrzebski closed 5 years ago

tdjastrzebski commented 5 years ago

I am trying to figure out if/how xregexp can be used to match and replace strings within the outermost matching curly braces trying to implement params name for value substitution - quite classical problem. Is such functionality currently supported? Namely: recursion or balancing groups. I know about matchRecursive() method but it does not seem to do what I need. Besides, it throws Unbalanced delimiter exception when string like ${{}param} is encountered. Sample code: let r = XRegExp.matchRecursive('${param1} test ${{}param2}', '\\${', '}', 'g'); Expected result: ['param1', '{}param2']

slevithan commented 5 years ago

See my reply to #272. Using '\\${|{' (rather than '\\${') as the left delimiter should give you what you want.

tdjastrzebski commented 4 years ago

thank you!

tdjastrzebski commented 4 years ago

Although, the solution does not exactly solve the problem because I need to match ${x} only and ignore {x}.