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"

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset