More on Character Classes (Regex)

This lesson discusses the character classes of regular expressions in detail.

Complement of a character class

So far, we’ve used character classes like [aeiou] (listing all allowed characters literally) and [a-z] (specifying a range of characters).

There’s more to these.

We can negate classes by prepending a not character (^) inside the square brackets. For example, [^AEIOUaeiou] allows every character that’s not a vowel. So, we can find all words that don’t start with a vowel:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy