Skip to main content
Skip table of contents

Regular Expressions

cheat sheet 

https://cheatography.com/davechild/cheat-sheets/regular-expressions/

Metacharacters

\aMatch a BELL, \u0007
\AMatch at the beginning of the input. Differs from ^ in that \A will not match after a new line within the input.
\bMatch if the current position is a word boundary. Boundaries occur at the transitions between word (\w) and non-word (\W) characters, with combining marks ignored.
\BMatch if the current position is not a word boundary.
\cXMatch a control-X character.
\dMatch any character with the Unicode General Category of Nd (Number, Decimal Digit.)
\DMatch any character that is not a decimal digit.
\eMatch an ESCAPE, \u001B.
\ETerminates a \Q…\E quoted sequence.
\fMatch a FORM FEED, \u000C.
\GMatch if the current position is at the end of the previous match.
\hMatch a Horizontal White Space character. They are characters with Unicode General Category of Space_Separator plus the ASCII tab (\u0009).
\HMatch a non-Horizontal White Space character.
\kNamed Capture Back Reference.
\nMatch 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.
\QQuotes all following characters until \E.
\rMatch a carriage return, \u000D.
\RMatch a new line character, or the sequence CR LF.
\sMatch a white space character.
White space is defined as [\t\n\f\r\p{Z}]. \SMatch a non-white space character.
\tMatch a horizontal tabulation, \u0009.
\uhhhhMatch the character with the hex value hhhh.
\UhhhhhhhhMatch the character with the hex value hhhhhhhh. Exactly eight hex digits must be provided, even though the largest Unicode code point is \U0010ffff.
\vMatch a new line character.
\VMatch a non-new line character.
\wMatch a word character.
\WMatch a non-word character.
\x{hhhh}Match the character with hex value hhhh. From one to six hex digits may be supplied.
\xhhMatch the character with two digit hex value hh
\XMatch a Grapheme Cluster .
\ZMatch if the current position is at the end of input, but before the final line terminator, if one exists.
\zMatch if the current position is at the end of input.
\nBack Reference. Match whatever the nth capturing group matched. n must be a number > 1 and < total number of capture groups in the pattern.
\0oooMatch an Octal character. 'ooo' is from one to three octal digits. 0377 is the largest allowed Octal character. The leading zero is required; it distinguishes Octal constants from back references.
[…]Match any one character from the set.
.Match any character.
^Match at the beginning of a line.
$Match at the end of a line.
\Quotes the following character. Characters that must be quoted to be treated as literals are * ? + [ ( ) { } ^ $ | \ .
\Quotes the following character. Characters that must be quoted to be treated as literals are [ ] \

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 as few times as possible.
??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 as few times as possible, but not less than n.
*+Match 0 or more times. Match as many times as possible when first encountered, do not retry with fewer even if overall match fails (Possessive Match)
++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. Range of input that matched the parenthesized subexpression is available after the match.
(?:…)Non-capturing parentheses. Groups the included pattern, but does not provide capturing of matching text. Somewhat more efficient than capturing parentheses.
(?>…)Atomic-match parentheses. First match of the parenthesized subexpression is the only one tried; if it does not lead to an overall pattern match, back up the search for a match to a position before the "(?>"
(?#…)Free-format comment (?# comment ).
(?=…)Look-ahead assertion. True if the parenthesized pattern matches at the current input position, but does not advance the input position.
(?!…)Negative look-ahead assertion. True if the parenthesized pattern does not match at the current input position. Does not advance the input position.
(?<=…)Look-behind assertion. True if the parenthesized pattern matches text preceding the current input position, with the last character of the match being the input character just before the current position. Does not alter the input position. The length of possible strings matched by the look-behind pattern must not be unbounded (no * or + operators.)
(?…)Negative Look-behind assertion. True if the parenthesized pattern does not match text preceding the current input position, with the last character of the match being the input character just before the current position. Does not alter the input position. The length of possible strings matched by the look-behind pattern must not be unbounded (no * or + operators.)
(?…)Named capture group. The are literal - they appear in the pattern.
(?ismwx-ismwx:…)Flag settings. Evaluate the parenthesized expression with the specified flags enabled or -disabled.
(?ismwx-ismwx)Flag settings. Change the flag settings. Changes apply to the portion of the pattern following the setting. For example, (?i) changes to a case insensitive match.

Flags

iIf set, matching will take place in a case-insensitive manner.
xIf set, allow use of white space and #comments within patterns
sIf set, a "." in a pattern will match a line terminator in the input text. By default, it will not. Note that a carriage-return / line-feed pair in text behave as a single line terminator, and will match a single "." in a RE pattern.
mControl the behavior of ^ and $ in a pattern. By default these will only match at the start and end, respectively, of the input text. If this flag is set, ^ and $ will also match at the start and end of each line within the input text.
wControls the behavior of \b in a pattern.
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.