Sunday, 10 August 2014

Regex way of saying "search until X but not including X" is:

Regex way of saying "search until X but not including X" is:
(?:(?!X).)*
where X can be any regular expression.
This is using a lookahead assertion, more specifically a negative lookahead.  Explanation:
(?:       # Match the following any number of times: 
 (?!lazy) # (first assert that it's not possible to match "lazy" here  
 .        # then match any character  
)*        # end of group, zero or more repetitions.

No comments:

Post a Comment