Special Characters: Quantifiers
Get introduced to the different types of quantifiers and their examples.
We'll cover the following...
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 it’ll |