I need tofind MATCH only if it is between START and STOP:
blah START hello MATCH bye STOP blah
blah START hello MATCH STOP blah
blah MATCH blah START hello MATCH STOP blah
e.g.: on line 3, only the 2nd MATCH should be found.
Please no开发者_开发知识库te that START, STOP and MATCH are not literals. They are expressed as parts regex of the regex.
Of course, a simplified but non elegant solution would consist in extracting the part between START and STOP and then looking for MATCH in there.
TIA,
@"START.*?(MATCH).*?STOP"
Just capture whatever "MATCH" is. You may have additional criteria for the things that can occur between START - MATCH - STOP (as opposed to just "."), if so, use a character class.
Try this:
/\bSTART\b.*?\bMATCH\b.*?\bSTOP\b/
Of if you're trying to capture it and are not speaking of these actual words:
/START.*?(MATCH).*?STOP/
精彩评论