Special Characters: Character Classes
Let's discuss one of the main components of a regular expression, i.e., character classes.
We'll cover the following...
As the name indicates, special characters are characters with extra meaning. You probably noticed a lot of characters in the previous lesson’s example that, although not strange, don’t really make much sense in the way they’re arranged. For example, there are a few +
and even some ?
that modify the behavior of the rest of the expression.
So, in order to start understanding how to read and write regular expressions, the first thing you need to understand is how to interpret these characters.
Interpretation of character classes
Character classes are everything you put inside brackets. Essentially, you’re letting the parser know which characters you want to match.
For example, /[abc]/
would match the first ‘a’ inside the string: bbbabcdebbb. Why just the first one? Because that’s how the default behavior of the parser works. If you want to change that, you’ll need to use flags (more on this in a moment).
Examples of character classes
Adding characters into your character class is perfectly fine. ...