RegEx Series: (Part 2) Special Characters & Quantifiers

R.
3 min readOct 9, 2020

Introduction

I promised that in this blog post that I would introduce how to use quantifiers with special and meta characters. The great thing about quantifiers is that you can use them to tell how many times a character should repeat. For example, when I introduced character sets, we might try to match a pattern such as

/[a-z]11/gi

This would mean that only the first character would be an alphabetical character of ‘a’ through ‘z’ and the next characters would be ‘1’ and ‘1’. However, what if we wanted to match a string where the first four characters were alphabetical followed by our two 1's? We might have to write it out in multiple character sets or we can specify with quantifiers. Let’s look at the picture below.

To add a quantifier after the pattern I am looking for, you add in curly braces {} and inside of those{4}, you can add in the number of times you want to match that pattern. In this case, I want to match anything that has exactly 4 alphabetical characters before two 1’s in it.

We can get more specific and give it an end condition {start, end}.

--

--