From the course: Learning Regular Expressions
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Negative lookahead assertions - Regular Expressions Tutorial
From the course: Learning Regular Expressions
Negative lookahead assertions
- The opposite of a positive lookahead assertion is a negative lookahead assertion and that's what we'll learn about in this movie. A negative lookahead assertion is true if the grouped expression is not found ahead of the current position. If the assertion fails, the match fails. If the assertion's true, then the match continues being evaluated. Just like positive lookahead assertions, they return true or false and they're not included in the match and they don't capture anything. A negative lookahead assertion is defined by putting a question mark and an exclamation point as the first two characters in the group. The question mark modifies the group. The exclamation point makes the group into a negative lookahead assertion. You can remember the exclamation point because it's frequently used to mean not in programming, as in not equal. It's literally the opposite of a positive lookahead assertion. In this example…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.