I have a multi-line string like this:
"...Togo...Togo...Togo...ACTIVE..."
I want to get everything between the third ‘Togo’ and ‘ACTIVE’ and the remainder of the string. I am unable to create a regular expression that can do this. If I try something like
reg = "(Togo^[Togo]*?)(ACTIVE.*)"
nothing is captured (the first and last parentheses are needed for capturing groups).
This matches just the desired parts:
The leading
.*is greedy, so the followingTogomatches at the last possible place. The captured part starts at the lastTogo.In your expression
^[Togo]*?doesn’t do the right thing.^tries to match the beginning of a line and[Togo]matches any of the charactersT,oorg. Even[^Togo]wouldn’t work since this just matches any character that is notT,oorg.