Regular Expressions Quick Reference
Regular Expressions Quick Reference
Regular Expressions Quick Reference
[set]
[^set]
[az]
[^az]
.
\char
Use
\t
\v
\b
\e
\r
\f
\n
\a
\c char
To match
Horizontal tab
Vertical tab
Backspace
Escape
Carriage return
Form feed
New line
Bell (alarm)
ASCII control
character
Unicode
\u0009
\u000B
\u0008
\u001B
\u000D
\u000C
\u000A
\u0007
Use
\octal
\x hex
\u hex
Use
To match character
\p{ctgry} In that Unicode category or block
\P{ctgry} Not in that Unicode category or
block
\w
Word character
\W
Non-word character
\d
Decimal digit
\D
Not a decimal digit
\s
White-space character
\S
Non-white-space char
Use
(exp)
(?<name>exp)
(?<name1name2>exp)
(?:exp)
(?=exp)
(?>exp)
Noncapturing group
Zero-width positive
lookahead
Zero-width negative
lookahead
Zero-width positive
lookbehind
Zero-width negative
lookbehind
Non-backtracking (greedy)
Option
i
m
n
s
x
Effect on match
Case-insensitive
Multiline mode
Explicit (named)
Single-line mode
Ignore white space
Use
(?imnsximnsx)
(?imnsximnsx:exp)
To
Set or disable the specified
options
Set or disable the specified
options within the
expression
(?!exp)
(?<=exp)
Greedy
*
+
?
{n}
{n,}
{n,m}
Use
^
\A
\z
\Z
$
\G
\b
\B
Lazy
*?
+?
??
{n}?
{n,}?
{n,m}?
Matches
0 or more times
1 or more times
0 or 1 time
Exactly n times
At least n times
From n to m times
To specify position
At start of string or line
At start of string
At end of string
At end (or before \n at end) of string
At end (or before \n at end) of string
or line
Where previous match ended
On word boundary
Not on word boundary
To define
Indexed group
Named group
Balancing group
(?<!exp)
June 2014
2014 Microsoft. All rights reserved.
Use
\n
\k<name>
To match
Indexed group
Named group
Use
a |b
(?(exp)
yes | no)
(?(name)
yes | no)
To match
Either a or b
yes if exp is matched
no if exp isn't matched
yes if name is matched
no if name isn't matched
Use
$n
$$
$&
$`
$'
$+
$_
To substitute
Substring matched by group
number n
Substring matched by group
name
Literal $ character
Copy of whole match
Text before the match
Text after the match
Last captured group
Entire input string
Use
(?# comment)
#
To
Add inline comment
Add x-mode comment
${name}
Category
Lu
LI
Lt
Lm
Lo
L
Mn
Mc
Me
M
Nd
Nl
No
N
Pc
Pd
Ps
Pe
Pi
Pf
Po
P
Sm
Sc
Sk
So
S
Zs
Zl
Zp
Z
Cc
Cf
Cs
Co
Cn
C
Description
Letter, uppercase
Letter, lowercase
Letter, title case
Letter, modifier
Letter, other
Letter, all
Mark, nonspacing combining
Mark, spacing combining
Mark, enclosing combining
Mark, all diacritic
Number, decimal digit
Number, letterlike
Number, other
Number, all
Punctuation, connector
Punctuation, dash
Punctuation, opening mark
Punctuation, closing mark
Punctuation, initial quote mark
Puntuation, final quote mark
Punctuation, other
Punctuation, all
Symbol, math
Symbol, currency
Symbol, modifier
Symbol, other
Symbol, all
Separator, space
Separator, line
Separator, paragraph
Separator, all
Control code
Format control character
Surrogate code point
Private-use character
Unassigned
Control characters, all
Class: System.Text.RegularExpressions.Regex