It’s possible to match a character from within a set of characters.
/[aeiou]/g matches all vowels in our input strings.
Here’s another example of these in action:
We match a
p, followed by one of the vowels, followed by a
There’s an intuitive shortcut for matching a character from within a continuous range.
/[a-z]/g matches only one character. In the example above, the strings have several matches each, each one character long. Not one long match.
We can combine ranges and individual characters in our regexes.
/[A-Za-z0-9_-]/g matches a single character, which must be (at least) one of the following:
- one of
We can also “negate” these rules:
The only difference between the first regex of this chapter and
/[^aeiou]/g is the
^ immediately after the opening bracket. Its purpose is to negate the rules defined within the brackets. We are now saying:
“match any character that is not any of