How to make lookbehind be greedy?
In this case, I want lookbehind to consume: if is present.
m = Regex.Match("From: John", @"(?i)(?<=from:)....");
m = Regex.Match("From: John", @"(?i)(?<=from:?)....");
I found a job around
@"(?i)(?<=\bsubject:?\s+).*?(?=\s*\r?$)"
As long as you put some affirmative after? then he gains an optional greedy exit from the game. For the same reason, I had to put $ on hold.
But if you need to end optional greed, then you need to go with the accepted answer below.
source
share