The title is not clear, so I write some sample to explain.
There is a string, which contains many nested {}s:
/users/{<\w{2,4}\d{3}>id}
You can see I use {} as a placeholder for path variables, and it can have regex inside and which can also have {}.
How to write a regex with java to parse the path pattern, find the {} parts which don’t have outer {}. For this example, it should be {<\w{2,4}\d{3}>id}.
Thanks~
UPDATE
The given example is too simple, it can be:
/users/{<\w{2,4}\d{3}>id}/{action}/{<\w{2,4}\d{3}>targetId}
The result should be:
{<\w{2,4}\d{3}>id}
{action}
{<\w{2,4}\d{3}>targetId}
So \\{.*\\} doesn’t work.
Will you have such case as
/users/{regex1}/{regex2}?If yes, in this case
"\\{.*\\}"will return"{regex1}/{regex2}". 🙁If not
"\\{(.*)\\}"is good enough, being greedy you’ll go for the whole expression you asked for. 😉EDIT:
With your edited question then the comment from @aix above was the right answer :
Find the `{}` part which doesn't have outer `{}` by regex
He pointed out your problem is similar with the one solved there: Regular Expression to match outer brackets