O'Reilly logo

JavaScript Regular Expressions by Gabriel Manricks, Loiane Groner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Character sets

In the following table, you can find the patterns for character sets, which tell the Regex to match only one character out of several characters.

Pattern

Description

Example

[xyz]

This matches any one character enclosed in the character set. You can use a hyphen to denote the range. For example, /[a-z]/ matches any letter in the alphabet and matches /[0-9]/ to any single digit.

/[ao]/ matches "a" in "bar"

[^xyz]

This matches any one character, which is not enclosed in the character set.

/[^ao]/ matches "b" in "bar"

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required