I'm trying to write a regex to capture all substrings in form of ++
+text+--
in a given input. So an example input could be:
Some text ++ not interesting text ++interesting part1-- and again some more text ++interesting part2-- and more text and ...
which I'd like to extract ++interesting part1--
and ++interesting part2--
.
My regex attempts
Obviously
++.*?--
does not work. Because for input above it matches "++ not interesting text ++interesting part1--" which is wrong.My other broken solution was the following regex
++(?!.*++).*--
which only captures the second instance ("interesting part2").
Any explanation and answer is welcome.
Note: I do want to solve the issue with regex to master it, though I know the problem has easier solution by just looking for ++
and --
indices repeatedly.