Lesson 7
Using Subexpressions
Metacharacters and character matching provide the basic power behind regular expressions, as has been demonstrated in the lessons thus far. In this lesson you’ll learn how to group expressions together using subexpressions.
Understanding Subexpressions
Matching multiple occurrences of a character was introduced in Lesson 5, “Repeating Matches.” As discussed in that lesson, \d+
matches one or more digits, and https?://
matches http://
or https://
.
In both of these examples (and indeed, in all the examples thus far) the repetition metacharacters (?
or *
or {2}
, for example) apply to the previous character or metacharacter.
For example, HTML developers often place nonbreaking spaces (using
) between words to ...
Get Learning Regular Expressions, First Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.