Show/Hide Toolbars

A character class matches any one of a set of characters. Character classes include the language elements listed in table 1.

Character class

Description

[ character_group ]

Matches any single character in character_group. By default, the match is case-sensitive.

[^ character_group ]

Negation: Matches any single character that is not in character_group. By default, characters in character_group are case-sensitive.

[ first - last ]

Character range: Matches any single character in the range from first to last.

.

Wildcard: Matches any single character except \n.

To match a literal period character (. or \u002E), you must precede it with the escape character (\.).

\p{ name }

Matches any single character in the Unicode general category or named block specified by name.

\P{ name }

Matches any single character that is not in the Unicode general category or named block specified by name.

\w

Matches any word character.

\W

Matches any non-word character.

\s

Matches any white-space character.

\S

Matches any non-white-space character.

\d

Matches any decimal digit.

\D

Matches any character other than a decimal digit.

Table 1: character classes

Pattern

Matches

[ae]

"a" in "gray"

"a", "e" in "lane"

[^aei]

"r", "g", "n" in "reign"

[A-Z]

"A", "B" in "AB123"

a.e

"ave" in "nave"

"ate" in "water"

\p{Lu}

\p{IsCyrillic}

"C", "L" in "City Lights"

"Д", "Ж" in "ДЖem"

\P{Lu}

\P{IsCyrillic}

"i", "t", "y" in "City"

"e", "m" in "ДЖem"

\w

"I", "D", "A", "1", "3" in "ID A1.3"

\W

" ", "." in "ID A1.3"

\w\s

"D " in "ID A1.3"

\s\S

" _" in "int __ctr"

\d

"4" in "4 = IV"

\D

" ", "=", " ", "I", "V" in "4 = IV"

Table 2: Examples for character classes

© 2021 AFRY Austria GmbH, www.redbex.com