Trying to read between the lines, it looks like you donβt want to look here, you really want not greedy .*? .
(?<=start).*?(?:end)?$
I assume that you are trying to match something like "start123end" , but do not want end or start appear in the matching text, and thus you have converse statements there to restrict .* , Which is usually greedy.
Instead, you can use the unwanted option and snap the right end of the pattern with $ .
(Alternatively, if you can use capture groups, you should simply do this:
start(.*?)(end)?$
and then just get the value from the first capture group.)
Amber
source share