Metacharacters
Metacharacters are reserved characters, and they are:
{}[]()^$.|*+?-\
Find a character
a
|
a single character a
| |
[abc]
|
(a|b|c)
|
any single
character from the set, i.e. a, b, or c. For example, [bcr]at matches "bat",
"cat", and "rat"
|
[^abc]
|
any single
character except a, b, or c. For example, [^b]at matches "cat" and "rat", but not "bat"
| |
[A-Z]
|
any character in the range A-Z, i.e. any uppercase letter
| |
[a-z]
|
any character in the range a-z, i.e. any lowercase letter
| |
[A-Za-z]
|
any character in the range A-Z or a-z, i.e. any letter
| |
[0-9]
|
\d
|
any character in the range 0-9, i.e. any number
|
.
|
any single character
| |
\.
|
a dot (prefix with a backslash as . is a metacharacter)
| |
\\
|
a backslash character (prefix with a backslash as the backslash is a
metacharacter itself)
| |
\t
|
a tab character
| |
\n
|
a new line character (also see $ is the end of line expression)
| |
\s
|
any whitespace character, which includes space, tab and newline
character
| |
\w
|
[0-9a-zA-Z_]
|
any word character, which only includes any lowercase or
uppercase letter, any number and the underscore character
|
\d
|
any digit
| |
(a|b)
|
a or b
|
Line Characters
^
|
start of line
|
$
|
end of line
|
^$
|
empty string = ""
|
Quantification
a?
|
0 or 1 of a. For example, colou?r matches both "color" and
"colour"
|
a*
|
0 or more of a. For example, ab*c matches "ac", "abc",
"abbc", "abbbc",
and so on
|
a+
|
1 or more of a. For example, ab+c matches "abc", "abbc", "abbbc",
and so on, but not "ac"
|
a{3}
|
exactly 3 of a
|
a{3,}
|
3 or more of a
|
a{3,6}
|
between 3 and 6 of a
|
Grouping
( )
|
capture group
|
\1
|
backreference to group #1
|
See also https://www.regular-expressions.info/index.html
No comments:
Post a Comment