I’ve been looking around and could not make this happen. I am not totally noob.
I need to get text delimited by (including) START and END that doesn’t contain START. Basically I can’t find a way to negate a whole word without using advanced stuff.
Example string:
abcSTARTabcSTARTabcENDabc
The expected result:
STARTabcEND
Not good:
STARTabcSTARTabcEND
I can’t use backward search stuff. I am testing my regex here: http://www.regextester.com
Thanks for any advice.
The really pedestrian solution would be
START(([^S]|S*S[^ST]|ST[^A]|STA[^R]|STAR[^T])*(S(T(AR?)?)?)?)END. Modern regex flavors have negative assertions which do this more elegantly, but I interpret your comment about “backwards search” to perhaps mean you cannot or don’t want to use this feature.Update: Just for completeness, note that the above is greedy with respect to the end delimiter. To only capture the shortest possible string, extend the negation to also cover the end delimiter —
START(([^ES]|E*E[^ENS]|EN[^DS]|S*S[^STE]|ST[^AE]|STA[^RE]|STAR[^TE])*(S(T(AR?)?)?|EN?)?)END. This risks to exceed the torture threshold in most cultures, though.Bug fix: A previous version of this answer had a bug, in that
SSTARTcould be part of the match (the secondSwould match[^T], etc). I fixed this but by the addition ofSin[^ST]and addingS*before the non-optionalSto allow for arbitrary repetitions ofSotherwise.