Negative look-behind assertion (?<!...)


What is a negative look-behind assertion? How to use it?

How to write a regular expression to find words not ending with 'oo' in text like: ?



A negative look-behind assertion is a zero-width assertion that allows you to not match a subpattern left to the current position (look-behind) without moving the matching position. Negative look-behind assertion is expressed as (?<!pattern). For example:

(?<!\t)\w+   - matches a word that does not follow a tab

The regular expression to match find words ending without 'oo' is: Note that:

 *          - skip space characters
(\w+)       - capture the word
(?<!oo)     - is the word not ending with '00'?

Click the button to test this regular expression here online:

2013-01-31, 2547👍, 0💬