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.
Positive lookahead assertions - Regular Expressions Tutorial
From the course: Learning Regular Expressions
Positive lookahead assertions
- [Instructor] In this chapter, we will learn about lookaround assertions, which come in two types, lookahead and lookbehind, and those are further divided into positive and negative. We'll begin by looking at positive lookahead assertions. A positive lookahead assertion defines an expression that returns true only if it matches the characters after the current position in the string. In other words, it tells the regex engine to pause and check the content further down the line before it proceeds. You can think of it as an additional condition that must be met. If the lookahead expression fails, the whole match fails. If it succeeds, then the engine will continue. Assertions are different from other expressions because they're not included in the match and they're always non-capturing groups. Just remember, assertions only return true, false, not matched or captured text. Lookahead assertions are supported by most regular…
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.