Lookahead and lookbehind, backreferences, lazy versus greedy matching, named groups, catastrophic backtracking and flavor differences.
35 cards · basic cards · AI-written, checked twice. Edit anything.
- What does a positive lookahead assertion do?
Show answer
Asserts that what follows matches a pattern without consuming characters.
- What is the syntax for a positive lookahead?
Show answer
(?=...)
- What does a negative lookahead assertion do?
Show answer
Asserts that what follows does not match a pattern without consuming characters.
- What is the syntax for a negative lookahead?
Show answer
(?!...)
- What does a positive lookbehind assertion do?
Show answer
Asserts that what precedes matches a pattern without consuming characters.
- What is the syntax for a positive lookbehind?
Show answer
(?<=...)
- What does a negative lookbehind assertion do?
Show answer
Asserts that what precedes does not match a pattern without consuming characters.
- What is the syntax for a negative lookbehind?
Show answer
(?<!...)
- Key difference: lookahead vs lookbehind?
Show answer
Lookahead checks forward in the string, lookbehind checks backward.
- What is a backreference in regex?
Show answer
A reference to a previously captured group in the same pattern.
- How do you write a numbered backreference to group 1?
Show answer
\1
- In pattern (a+)\1, what does \1 match?
Show answer
The same text captured by the first group, i.e., the same sequence of a's.
- Name a common use case for backreferences.
Show answer
Matching repeated or doubled words, like finding the same word twice in a row.
- If a group is captured multiple times, what does a backreference refer to?
Show answer
The most recent capture of that group.
- What is a lazy quantifier?
Show answer
A quantifier that matches as few characters as possible while still allowing the overall pattern to succeed.