x Did you like it? Well, then please consider making a donation :)

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

PatternDescriptionSampleMatches
[ chars group ]Matches any single character in character_group. By default, the match is case-sensitive.[ae]"a" in "gray", "a", "e" in "lane"
[^ chars group ]Negation: Matches any single character that is not in character_group. By default, characters in character_group are case-sensitive.[^aei]"r", "g", "n" in "reign"
[ first - last ]Character range: Matches any single character in the range from first to last.[A-Z]"A", "B" in "AB123"
.Wildcard: Matches any single character except \n. To match a literal period character (. or \u002E), you must precede it with the escape character (\.).a.e"ave" in "nave", "ate" in "water"
\p{ name }Matches any single character in the Unicode general category or named block specified by name.\p{Lu}"C", "L" in "City Lights"
\P{ name }Matches any single character that is not in the Unicode general category or named block specified by name.\P{Lu}"i", "t", "y" in "City"
\wMatches any word character.\w"I", "D", "A", "1", "3" in "ID A1.3"
\WMatches any non-word character.\W" ", "." in "ID A1.3"
\sMatches any white-space character.\w\s"D " in "ID A1.3"
\SMatches any non-white-space character.\s\S" _" in "int __ctr"
\dMatches any decimal digit.\d"4" in "4 = IV"
\DMatches any character other than a decimal digit.\D" ", "=", " ", "I", "V" in "4 = IV"