Search⌘ K
AI Features

Special Characters: Quantifiers

Explore how quantifiers in JavaScript regular expressions let you specify the number of repetitions for characters or groups. Understand common quantifiers like +, *, ?, and {X,Y}, plus positional quantifiers for start/end matching. Discover conditional quantifiers such as lookaheads and lookbehinds to enhance pattern matching precision.

You now understand what a character class is, but if you try the examples from the previous lesson in regex101.com, you’ll see how you’re only matching one character. Here is where quantifiers come in handy. The point of quantifiers is to let the parser understand how many repetitions of the class can happen inside a given match.

Take into account that a character class encompasses several different characters, and a quantifier bigger than one means any of those can happen more than once.

Examples of quantifiers

Quantifiers, just like character classes, allow you to be fuzzy with the specifics, helping you set up dynamic patterns.

Quantifier Description Example
+ Helps you match any string that contains your pattern at least one time. /(ho)+/ will match hot but will not match anything without the “ho” in it.
* Similar to the previous quantifier, but the match is also valid if there are no instances of the pattern to be found. /[ho]*/ will match hot and also cold, but
...