Quick Start
Tutorial
Tools & Languages
Examples
Reference
Book Reviews
Regex Reference
Introduction
Table of Contents
Quick Reference
Characters
Basic Features
Character Classes
Shorthands
Anchors
Word Boundaries
Quantifiers
Unicode
Capturing Groups & Backreferences
Named Groups & Backreferences
Special Groups
Mode Modifiers
Recursion & Balancing Groups
Replacement Reference
Characters
Matched Text & Backreferences
Context & Case Conversion
Conditionals
More on This Site
Introduction
Regular Expressions Quick Start
Regular Expressions Tutorial
Replacement Strings Tutorial
Applications and Languages
Regular Expressions Examples
Regular Expressions Reference
Replacement Strings Reference
Book Reviews
Printable PDF
About This Site
RSS Feed & Blog
RegexBuddy—Better than a regular expression reference!

Regular Expressions Quick Reference

This quick reference is a summary of all the regex syntax that is listed in the full reference tables, without any explanation. You can use this table if you’ve seen some syntax in somebody else’s regex and you have no idea what feature that syntax is for. Follow the link to learn more about the syntax in the tutorial. Since the full reference tables cover a variety of regex flavors, this quick reference may have multiple entries for the same syntax with links to different sections in the tutorial if different regex flavors use the same syntax for different features.

If you already know the feature you want but forgot which syntax to use, look up the feature in the regex reference table of contents instead.

SyntaxFeature
Any character except [\^$.|?*+()Literal character
\ followed by any of [\^$.|?*+(){}Backslash escapes a metacharacter
.Any character
|Alternation
\|Alternation
?Greedy quantifier
\?Greedy quantifier
??Lazy quantifier
?+Possessive quantifier
*Greedy quantifier
*?Lazy quantifier
*+Possessive quantifier
+Greedy quantifier
\+Greedy quantifier
+?Lazy quantifier
++Possessive quantifier
{ and }Literal curly braces
{n} where n is an integer >= 1Fixed quantifier
{n,m} where n >= 0 and m >= nGreedy quantifier
{n,} where n >= 0Greedy quantifier
{,m} where m >= 1Greedy quantifier
\{n\} where n is an integer >= 1Fixed quantifier
\{n,m\} where n >= 0 and m >= nGreedy quantifier
\{n,\} where n >= 0Greedy quantifier
\{,m\} where m >= 1Greedy quantifier
{n,m}? where n >= 0 and m >= nLazy quantifier
{n,}? where n >= 0Lazy quantifier
{,m}? where m >= 1Lazy quantifier
{n,m}+ where n >= 0 and m >= nPossessive quantifier
{n,}+ where n >= 0Possessive quantifier
^String anchor
^Line anchor
$String anchor
$Line anchor
\aCharacter escape
\AString anchor
\AAttempt anchor
\bWord boundary
\bBackspace character
\BWord non-boundary
\BBackslash character
\cXML shorthand
\ca through \czControl character escape
\cA through \cZControl character escape
\CXML shorthand
\dDigits shorthand
\DNon-digits shorthand
\eEscape character
\fForm feed character
\g{name}Named backreference
\g-1, \g-2, etc.Relative Backreference
\g{-1}, \g{-2}, etc.Relative Backreference
\g1 through \g99Backreference
\g{1} through \g{99}Backreference
\g<name> where “name” is the name of a capturing groupNamed subroutine call
\g<name> where “name” is the name of a capturing groupNamed backreference
\g'name' where “name” is the name of a capturing groupNamed subroutine call
\g'name' where “name” is the name of a capturing groupNamed backreference
\g<0>Recursion
\g'0'Recursion
\g<1> where 1 is the number of a capturing groupSubroutine call
\g<1> where 1 is the number of a capturing groupBackreference
\g'1' where 1 is the number of a capturing groupSubroutine call
\g'1' where 1 is the number of a capturing groupBackreference
\g<-1> where -1 is a negative integerRelative subroutine call
\g<-1> where -1 is a negative integerRelative backreference
\g'-1' where -1 is a negative integerRelative subroutine call
\g'-1' where -1 is a negative integerRelative backreference
\g<+1> where +1 is a positive integerForward subroutine call
\g'+1' where +1 is a positive integerForward subroutine call
\GAttempt anchor
\GMatch anchor
\hHexadecimal digit shorthand
\hHorizontal whitespace shorthand
\HNon-hexadecimal digit shorthand
\HNon-horizontal whitespace shorthand
\iXML shorthand
\IXML shorthand
\k<name>Named backreference
\k'name' through \k'99'Named backreference
\k{name}Named backreference
\k<1> through \k<99>Backreference
\k'1' through \k'99'Backreference
\k<-1>, \k<-2>, etc.Relative Backreference
\k'-1', \k'-2', etc.Relative Backreference
\KKeep text out of the regex match
\lLowercase shorthand
\LNon-lowercase shorthand
\mTcl start of word boundary
\MTcl end of word boundary
\nLine feed character
\NNot a line break
Literal CRLF, LF, or CR line breakLine break
\o{7777} where 7777 is any octal numberOctal escape
\pL where L is a Unicode categoryUnicode category
\PL where L is a Unicode categoryUnicode category
\p{L} where L is a Unicode categoryUnicode category
\p{IsL} where L is a Unicode categoryUnicode category
\p{Category}Unicode category
\p{IsCategory}Unicode category
\p{Script}Unicode script
\p{IsScript}Unicode script
\p{Block}Unicode block
\p{InBlock}Unicode block
\p{IsBlock}Unicode block
\P{Property}Negated Unicode property
\p{^Property}Negated Unicode property
\P{^Property}Unicode property
\Q…\EEscape sequence
\rCarriage return character
\RLine break
\sWhitespace shorthand
\SNon-whitespace shorthand
\tTab character
\uUppercase shorthand
\uFFFF where FFFF are 4 hexadecimal digitsUnicode code point
\u{FFFF} where FFFF are 1 to 4 hexadecimal digitsUnicode code point
\UNon-uppercase shorthand
\vVertical tab character
\vVertical whitespace shorthand
\VNon-vertical whitespace shorthand
\wWord character shorthand
\WNon-word character shorthand
\xFF where FF are 2 hexadecimal digits Hexadecimal escape
\xFFFF where FFFF are 4 hexadecimal digitsUnicode code point
\x{FFFF} where FFFF are 1 to 4 hexadecimal digitsUnicode code point
\XUnicode grapheme
\yTcl word boundary
\YTcl word non-boundary
\ZString anchor
\zString anchor
\0NULL escape
\1 through \7Octal escape
\1 through \9Backreference
\10 through \77Octal escape
\10 through \99Backreference
\100 through \377Octal escape
\01 through \0377Octal escape
\`String anchor
\`Attempt anchor
\'String anchor
\<GNU word boundary
\>GNU word boundary
[[:<:]]POSIX word boundary
[[:>:]]POSIX word boundary
(regex)Capturing group
\(regex\)Capturing group
(?:regex)Non-capturing group
(?<name>regex)Named capturing group
(?'name'regex)Named capturing group
(?#comment)Comment
(?|regex)Branch reset group
(?>regex)Atomic group
(?=regex)Positive lookahead
(?!regex)Negative lookahead
(?<=regex)Positive lookbehind
(?<!regex)Negative lookbehind
(?(?=regex)then|else) where (?=regex) is any valid lookaround and then and else are any valid regexesLookaround conditional
(?(regex)then|else) where regex, then, and else are any valid regexes and regex is not the name of a capturing groupImplicit lookahead conditional
(?(name)then|else) where name is the name of a capturing group and then and else are any valid regexesNamed conditional
(?(<name>)then|else) where name is the name of a capturing group and then and else are any valid regexesNamed conditional
(?('name')then|else) where name is the name of a capturing group and then and else are any valid regexesNamed conditional
(?(1)then|else) where 1 is the number of a capturing group and then and else are any valid regexesConditional
(?(-1)then|else) where -1 is a negative integer and then and else are any valid regexesRelative conditional
(?(+1)then|else) where +1 is a positive integer and then and else are any valid regexesForward conditional
(?(+1)then|else) where 1 is the number of a capturing group and then and else are any valid regexesConditional
(?<capture-subtract>regex) where “capture” and “subtract” are group names and “regex” is any regexBalancing group
(?'capture-subtract'regex) where “capture” and “subtract” are group names and “regex” is any regexBalancing group
(?&name) where “name” is the name of a capturing groupNamed subroutine call
(?(DEFINE)regex) where “regex” is any regexSubroutine definitions
(?P<name>regex)Named capturing group
(?P=name)Named backreference
(?P=1) through (?P=99)Backreference
(?P>name) where “name” is the name of a capturing groupNamed subroutine call
(?R)Recursion
(?0)Recursion
(?1) where 1 is the number of a capturing groupSubroutine call
(?-1) where -1 is a negative integerRelative subroutine call
(?+1) where +1 is a positive integerForward subroutine call

Character Class SyntaxFeature
Any character except ^-]\Literal character
\ (backslash) followed by any of ^-]\Backslash escapes a metacharacter
\Literal backslash
- between two tokens that each specify a single characterRange
^ immediately after the opening [Negated character class
[Literal opening bracket
[Nested character class
[base-[subtract]]Character class subtraction
[base&&[intersect]]Character class intersection
[base&&intersect]Character class intersection
[:alpha:]POSIX class
[:^alpha:]Negated POSIX class
\p{Alpha}POSIX class
\p{IsAlpha}POSIX class
[.span-ll.]POSIX collation sequence
[=x=]POSIX character equivalence