Book Image

JavaScript Regular Expressions

By : Gabriel Manricks, Loiane Groner, Loiane Groner [Duplicate entry]
Book Image

JavaScript Regular Expressions

By: Gabriel Manricks, Loiane Groner, Loiane Groner [Duplicate entry]

Overview of this book

Table of Contents (13 chapters)

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"