Metacharacters
\A
Match at the beginning of the input.
\b
Match if the current position is a word boundary.
\B
Match if the current position is not a word boundary.
\cX
Match a control-X character.
\d
Match any character with the Unicode General Category of Nd (Number, Decimal Digit.)
\D
Match any character that is not a decimal digit.
\e
Match an ESCAPE, \u001B.
\E
Terminates a \Q…\E quoted sequence.
\f
Match a FORM FEED, \u000C.
\G
Match if the current position is at the end of the previous match.
\h
Match a Horizontal White Space character.
\H
Match a non-Horizontal White Space character.
\k
Named Capture Back Reference.
\n
Match a line feed, \u000A.
\N{unicode}
Match the named character.
\p{unicode}
Match any character with the specified Unicode Property.
\P{unicode}
Match any character not having the specified Unicode Property.
\Q
Quotes all following characters until \E.
\r
Match a carriage return, \u000D.
\R
Match a new line character, or the sequence CR LF.
\s
Match a white space character.
\S
Match a non-white space character.
\t
Match a horizontal tabulation, \u0009.
\uhhhh
Match the character with the hex value hhhh.
\Uhhhhhhhh
Match the character with the hex value hhhhhhhh.
\v
Match a new line character.
\V
Match a non-new line character.
\w
Match a word character.
\W
Match a non-word character.
\x{hhhh}
Match the character with hex value hhhh.
\xhh
Match the character with two digit hex value hh
\X
Match a Grapheme Cluster .
\Z
Match if the current position is at the end of input, but before the final line terminator, if one exists.
\z
Match if the current position is at the end of input.
\n
Back Reference. Match whatever the nth capturing group matched. n must be a number > 1 and < total number of capture groups in the pattern.
\0ooo
Match an Octal character.
[…]
Match any one character from the set.
^
Match at the beginning of a line.
$
Match at the end of a line.
\
Quotes the following character.
\
Quotes the following character.
Operators
|
Alternation. A|B matches either A or B.
*
Match 0 or more times. Match as many times as possible.
+
Match 1 or more times. Match as many times as possible.
?
Match zero or one times. Prefer one.
{n}
Match exactly n times
{n,}
Match at least n times. Match as many times as possible.
{n,m}
Match between n and m times. Match as many times as possible, but not more than m.
*?
Match 0 or more times. Match as few times as possible.
+?
Match 1 or more times.
??
Match zero or one times. Prefer zero.
{n}?
Match exactly n times
{n,}?
Match at least n time§s, but no more than required for an overall pattern match
{n,m}?
Match between n and m times.
*+
Match 0 or more times.
++
Match 1 or more times. Possessive match.
?+
Match zero or one times. Possessive match.
{n}+
Match exactly n times
{n,}+
Match at least n times. Possessive Match.
{n,m}+
Match between n and m times. Possessive Match.
(…)
Capturing parentheses.
(?:…)
Non-capturing parentheses.
(?>…)
Atomic-match parentheses.
(?#…)
Free-format comment (?# comment ).
(?=…)
Look-ahead assertion.
(?!…)
Negative look-ahead assertion.
(?<=…)
Look-behind assertion.
(?<!…)
Negative Look-behind assertion.
(?…)
Named capture group. The
are literal - they appear in the pattern.
(?ismwx-ismwx:…)
Flag settings.
(?ismwx-ismwx)
Flag settings.
Set Expressions
[abc]
Match any of the characters a, b or c
[^abc]
Negation - match any character except a, b or c
[A-M]
Range - match any character from A to M. The characters to include are determined by Unicode code point ordering.
[\u0000-\U0010ffff]
Range - match all characters.
Flags
i
If set, matching will take place in a case-insensitive manner.
x
If set, allow use of white space and #comments within patterns
s
If set, a "." in a pattern will match a line terminator in the input text. By default, it will not.
m
Control the behavior of ^ and $ in a pattern.
will also match at the start and end of each line within the input text.
w
Controls the behavior of
\b in a pattern.
If set, word boundaries are found according to the definitions of word found in Unicode UAX 29, Text Boundaries.
By default, word boundaries are identified by means of a simple classification of characters as either “word” or “non-word”, which approximates traditional regular expression behavior. The results obtained with the two options can be quite different in runs of spaces and other non-word characters.
More
Complete reference you will find on ICU User Guide website.
License
Above RegEx reference is reproduced from the ICU User Guide, Copyright (c) 2000 - 2009 IBM and Others, which is licensed under the following terms:
COPYRIGHT AND PERMISSION NOTICE
Copyright (c) 1995-2009 International Business Machines Corporation and others. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder.
All trademarks and registered trademarks mentioned herein are the property of their respective owners.