I want to make a regex to capture a string of format test1 anything here
or anything here test2
, but not test1 anything here test2
.
Is there a way to write a regex for this? Basically, I want something like /^(test1 )?(.*)$( test2)?/i
, but preventing test1 and test2 from both appearing. Also, my example is wrong because it never gets past the 2nd capturing group... How can I do this?
Edit: I want to be able to capture the anything here
part, so it needs to be inside its own capturing group.