Thursday, October 13, 2016

matcher

Subexpression
Matches
^
Matches beginning of line.
$
Matches end of line.
.
Matches any single character except newline. Using m option allows it to match newline as well.
[...]
Matches any single character in brackets.
[^...]
Matches any single character not in brackets
\A
Beginning of entire string
\z
End of entire string
\Z
End of entire string except allowable final line terminator.
re*
Matches 0 or more occurrences of preceding expression.
re+
Matches 1 or more of the previous thing
re?
Matches 0 or 1 occurrence of preceding expression.
re{ n}
Matches exactly n number of occurrences of preceding expression.
re{ n,}
Matches n or more occurrences of preceding expression.
re{ n, m}
Matches at least n and at most m occurrences of preceding expression.
a| b
Matches either a or b.
(re)
Groups regular expressions and remembers matched text.
(?: re)
Groups regular expressions without remembering matched text.
(?> re)
Matches independent pattern without backtracking.
\w
Matches word characters.
\W
Matches nonword characters.
\s
Matches whitespace. Equivalent to [\t\n\r\f].
\S
Matches nonwhitespace.
\d
Matches digits. Equivalent to [0-9].
\D
Matches nondigits.
\A
Matches beginning of string.
\Z
Matches end of string. If a newline exists, it matches just before newline.
\z
Matches end of string.
\G
Matches point where last match finished.
\n
Back-reference to capture group number "n"
\b
Matches word boundaries when outside brackets. Matches backspace (0x08) when inside brackets.
\B
Matches nonword boundaries.
\n, \t, etc.
Matches newlines, carriage returns, tabs, etc.
\Q
Escape (quote) all characters up to \E
\E
Ends quoting begun with \Q
No.
Character Class
Description
1
[abc]
a, b, or c (simple class)
2
[^abc]
Any character except a, b, or c (negation)
3
[a-zA-Z]
a through z or A through Z, inclusive (range)
4
[a-d[m-p]]
a through d, or m through p: [a-dm-p] (union)
5
[a-z&&[def]]
d, e, or f (intersection)
6
[a-z&&[^bc]]
a through z, except for b and c: [ad-z] (subtraction)
7
[a-z&&[^m-p]]
a through z, and not m through p: [a-lq-z](subtraction)


No comments:

Post a Comment