I\'m stuck on a RegEx problem that\'s seemingly very simple and yet I can\'t get it working.
Suppose I have input like this:
Some text %interestingbi
Try this:
%interestingbit%(?:(.+)(?OPTIONAL_THING))?(.+?)%anotherinterestingbit%
First there's a non-capturing group which matches .+OPTIONAL_THING
or nothing. If a match is found, there's the named group inside, which captures OPTIONAL_THING
for you. The rest is captured with .+?%anotherinterestingbit%
.
[edit]: I added a couple of parentheses for additional capture groups, so now the captured groups match the following:
Are these the three matches you're looking for?