Regular Expression Syntax Used in Pattern Matching

A regular expression is a pattern of text that consists of ordinary characters, for example, letters a through z, and special characters.
Character(s) Matches in searched string
pattern Matches pattern anywhere in the name.
\ Marks the next character as either a special character, a literal, a back reference, or an octal escape. For example, 'd' matches the character "d". ' \d' matches a digit character. The sequence '\\' matches "\" and "\(" matches "(".
. Matches any single character.
^ Matches the position at the beginning of the searched string. For example ^CF matches any string starting 'CF'.
$ Matches the position at the end of the searched string. For example EZ$ matches any string ending 'EZ'.
? Matches the preceding subexpression zero or one time. For example, "mast(er)?" matches "mast" or "master". Also, see below for additional uses of '?'.
* Matches the preceding subexpression zero or more times. For example, zo* matches "z" and "zoo".
+ Matches the preceding subexpression one or more times. For example, 'zo+' matches "zo" and zoo", but not "z".
{n} Matches exactly n times, where n is a nonnegative integer. For example, 'o{2}' matches the two o's in "zoo", but not the o in "zero".
{n,} Matches at least n times, where n is a nonnegative integer. For example, 'o{2,}' matches all the o's in "zooooom" but not the o in "zero".
{n,m} Matches at least n times and at most m times, where n and m are nonnegative integers ( n <= m). For example, 'o{2,4}' matches the first four o's in "zooooom", but not the o in "zero".
? When '?' immediately follows any of the qualifiers (*, +, ?, {n}, {n,}, {n,m}), the matching pattern is non-greedy. While the default pattern matching is to match as much of the searched string as possible, a non-greedy pattern matches as little of the searched string as possible. For example, 'o+?' matches a single o in "zooom", while 'o+' matches all the o's.
(pattern) Matches pattern as a subexpression and remembers the match. The remembered match can be used in a following back reference (described below) or in the replacement string of a search and replace operation. To match the parentheses characters ( and ), use '\(' and '\)'.
x|y Matches either x or y. For example, 'MAST(ER|FILE)' matches either "MASTER" or "MASTFILE".
[charlist] Matches any single character in charlist. For example, '[aeiou]' matches the e in "Relativity".
[^charlist] Matches any single character not in charlist. For example, '[^aeiou]' matches the R in "Relativity".
[a-z] Matches any single character in the specified character range. For example, '[a-z]' matches any lowercase alphabetic character in the range "a" through "z", inclusive.
[^m-z] Matches any single character not in the specified character range. For example, '[^m-z]' matches any character except those in the range "m" through "z", inclusive.
\b Matches a word boundary (the position between a word and a space). For example, "le\b" matches the "le" of "file" in the searched string "lengthy file name", not the "le" in "lengthy".
\B Matches a non-word boundary. For example, "le\B" matches the "le" of "lengthy" in the searched string "lengthy file name", not the "le" in "file".
\d Matches a digit character (equivalent to [0-9]).
\D Matches a non-digit character (equivalent to [^0-9]).
\s Matches a white space character.
\S Matches a nonwhite space character.
\w Matches any word character including underscore (equivalent to [A-Za-z0-9_]).
\W Matches any non-word character (equivalent to [^A-Za-z0-9_]).
\num Matches a back reference to a remembered match, where num is a positive integer. For example, '(.)\1' matches two consecutive identical characters.