0% found this document useful (0 votes)
39 views2 pages

Character Class Description Pattern Matches

The document describes various character classes, quantifiers, anchors, and other elements that are used to define patterns in regular expressions. Character classes like [] match single characters, quantifiers like * match the previous element zero or more times, and anchors like ^ match the start or end of a string. Together these elements provide powerful pattern matching capabilities for strings.

Uploaded by

Liuba Dubinin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

Character Class Description Pattern Matches

The document describes various character classes, quantifiers, anchors, and other elements that are used to define patterns in regular expressions. Character classes like [] match single characters, quantifiers like * match the previous element zero or more times, and anchors like ^ match the start or end of a string. Together these elements provide powerful pattern matching capabilities for strings.

Uploaded by

Liuba Dubinin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Character class Description Pattern Matches

[ character_group ] Matches any single character in character_group. By default, the match is case- [ae] "a" in "gray"
sensitive. "a", "e" in lane"
[^ character_group ] Negation: Matches any single character that is not in character_group. By default, [^aei] "r", "g", "n" in "reign"
characters in character_group are case-sensitive.
[ 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. a.e "ave" in "nave"
"ate" in "water
To match a literal period character (. or \u002E), you must precede it with the escape
character (\.).
\w Matches any word character. \w "I", "D", "A", "1", "3" in "ID
A1.3"
\W Matches any non-word character. \W " ", "." in "ID A1.3"
\s Matches any white-space character. \w\s "D " in "ID A1.3"
\S Matches any non-white-space character. \s\S " _" in "int __ctr"
\d Matches any decimal digit. \d "4" in "4 = IV"
\D Matches any character other than a decimal digit. \D " ", "=", " ", "I", "V" in "4 =
IV"

Quantifier Description Pattern Matches


* Matches the previous element zero or more times. \d*\.\d ".0", "19.9", "219.9"
+ Matches the previous element one or more times. "be+" "bee" in "been", "be" in
"bent"
? Matches the previous element zero or one time. "rai?n" "ran", "rain"
{n} Matches the previous element exactly n times. ",\d{3}" ",043" in "1,043.6", ",876",
",543", and ",210" in
"9,876,543,210"
{ n ,} Matches the previous element at least n times. "\d{2,}" "166", "29", "1930"
{n,m} Matches the previous element at least n times, but no more than m times. "\d{3,5}" "166", "17668"

"19302" in "193024"
Anchors Description Pattern Matches
^ By default, the match must start at the beginning of the string; in multiline mode, it ^\d{3} "901" in
must start at the beginning of the line.
"901-333-"
$ By default, the match must occur at the end of the string or before \n at the end of -\d{3}$ "-333" in
the string; in multiline mode, it must occur before the end of the line or before \n at
the end of the line. "-901-333"

Misc. Description Pattern Matches


| Matches any one element separated by the vertical bar (|) character. th(e|is|at) "the", "this" in "this is the
day. "
\ When followed by a character that is not recognized as an escaped character in this and world\. "world." in "Hello world."
other tables in this topic, matches that character. For example, \* is the same as \x2A,
and \. is the same as \x2E. This allows the regular expression engine to disambiguate
language elements (such as * or ?) and character literals (represented by \* or \?).

You might also like