FlashKeepers

Programming Concepts · College · College and University

Regular Expressions II: Advanced Patterns

Lookahead and lookbehind, backreferences, lazy versus greedy matching, named groups, catastrophic backtracking and flavor differences.

About this set

35 basic cards for College Programming Concepts. Set 2 of 2 in Regular Expressions. It opens with "What does a positive lookahead assertion do?" and "What is the syntax for a positive lookahead?". Study it alongside the other College sets below.

35 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What does a positive lookahead assertion do?
Show answerAsserts 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 answerAsserts 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 answerAsserts 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 answerAsserts 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 answerLookahead checks forward in the string, lookbehind checks backward.
What is a backreference in regex?
Show answerA 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 answerThe same text captured by the first group, i.e., the same sequence of a's.
Name a common use case for backreferences.
Show answerMatching 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 answerThe most recent capture of that group.
What is a lazy quantifier?
Show answerA quantifier that matches as few characters as possible while still allowing the overall pattern to succeed.

20 more cards in the app

Study this set free