-1

Is there some solution how can I parse this string to 3 sections?

{ROW.{TABLE.{TEMP.lang}}}

To this

{ROW.{TABLE.{TEMP.lang}}}
{TABLE.{TEMP.lang}
{TEMP.lang}

For example when Iam trying replace TABLE. variable

{TABLE\.(.+)} = 1 => {TABLE.{TEMP.lang}}} 2 => {TEMP.lang}}
{TABLE\.(.+?)} = 1 => {TABLE.{TEMP.lang} 2 => {TEMP.lang

Thank you.

Petr Klein
  • 797
  • 2
  • 9
  • 23
  • You're actually trying to do a recursive match. There are similar answers to questions that might work for you (if adapted) [here](https://stackoverflow.com/questions/14952113/how-can-i-match-nested-brackets-using-regex) and [here](https://stackoverflow.com/questions/133601/can-regular-expressions-be-used-to-match-nested-patterns). – Pedro Corso Feb 07 '19 at 11:29
  • Possible duplicate of [How can I match nested brackets using regex?](https://stackoverflow.com/questions/14952113/how-can-i-match-nested-brackets-using-regex) – Nico Haase Feb 07 '19 at 11:40

1 Answers1

0

What you're trying to do is a recursive match. As I have already stated on my comment, there are similar answers to questions that might work for you (if adapted) here and here.

For your case, I adapted this answer for your situation, resulting in the following RegEx:

(?=(\{(?>[^{}]+|(?1))+\}))

I replaced the parenthesis (of the previous solution) for curly brackets and then enclosed the entire capturing group in a positive lookahead. Since lookarounds don't consume any characters, the engine will keep trying to match the string. Additionally, if you include the assertion in the lookahead inside a capturing group, the expression will be "matched" (but not consumed) and you'll be able to retrieve it from the capturing groups. This way, it's possble to match your pattern multiple times, giving you the expected results.

Regex101 demo: https://regex101.com/r/nsypuX/1/

Pedro Corso
  • 557
  • 8
  • 22