11.5. Fine-tuning regular expressions with quantifiers, anchors, and modifiers
Quantifiers let you specify how many times in a row you want something to match. Anchors let you stipulate that the match occur at a certain structural point in a string (beginning of string, end of line, at a word boundary, and so on). Modifiers are like switches you can flip to change the behavior of the regexp engine; for example, by making it case-insensitive or altering how it handles whitespace.
We’ll look at quantifiers, anchors, and modifiers here, in that order.
11.5.1. Constraining matches with quantifiers
Regexp syntax gives you ways to specify not only what you want but also how many: exactly one of a particular character, 5–10 repetitions of a subpattern, ...
Get The Well-Grounded Rubyist, Second 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.