I'm trying to parse the following pattern
(\d+)\*\[(.+?)\]
Here's the string I'd like for it to parse correctly:
10*[1*[{0.1-0.9}(10)]]10*[1*[{0.2-0.3}(10)]]
there should be 2 match here with their group 2 being:
1*[{0.1-0.9}(10)] and
1*[{0.2-0.3}(10)]
unfortunately due to the .+? the matches are now:
1*[{0.1-0.9}(10)
1*[{0.2-0.3}(10)
both of them are missing the closing [
, but the ? is needed otherwise I can't but them next to each other:
with the pattern being (\d+)\*\[(.+)\]
:
there is only 1 match with its group 2 being:
1*[{0.1-0.9}(10)]]10*[1*[{0.2-0.3}(10)]
Could anyone guide me on this issue? Maybe I need to do some kind of preparse? Pure regex would be much appreciated.
EDIT 1:
I would use this regular expression recursively thats why I need it to match both the inner and the outer pattern correctly, unfortunately both greedy and reluctant matching goes wrong with my pattern
EDIT 2:
My original question was vague, I'm sorry about that. Here's the catch, here's why I, myself couldn't do the correct regex string:
the pattern that matches 10*[1*[{0.1-0.9}(10)]]10*[1*[{0.2-0.3}(10)]]
correctly into 1*[{0.1-0.9}(10)]
and 1*[{0.2-0.3}(10)]
should also be able to match the matches itself:
e.g.: 1*[{0.1-0.9}(10)]
into 1
and {0.1-0.9}(10)
maybe I shouldn't try with pure regex?