.NET Regex

Regular expression:





.NET Regex is a tool for testing .NET regular expressions.

Silverlight is used if available, otherwise Ajax calls made to the server (the icon in the top-right indicates which). With Silverlight auto mode is used by default — the regular expression is automatically applied to the test input after every keystroke. Auto mode can be disabled by unchecking the checkbox. When auto mode is disabled either click on the Test button or press CTRL-Enter to run the test.

The regular expression and test input text areas can be resized by dragging the handles.

UI settings — auto-mode, text size, textbox heights — are stored automatically.

Regular expression text, test input text, and options, are stored in browser storage when the Save button is clicked. The amount of text that can be stored depends on the browser.


* Zero or more matches
+ One or more matches
? Zero or one matches
{n} Exactly n matches
{n,} At least n matches
{n,m} Between n and m matches
*? One or more non-greedy
?? Zero if possible or one match
{n}? Equivalent to {n}
{n,}? Specifies as few repeats as possible, but at least n
{n,m}? Specifies as few repeats as possible between n and m


^ Match at the beginning of string or line
$ Match match at the end of string, before \n, end of line
\A Match at the beginning of string (ignores Multiline option)
\Z Match at the end of the string or before \n (ignores the Multiline option)
\z Match at end of string (ignores the Multiline option)
\b Match at boundary between \w (alphanumeric) and \W (nonalphanumeric) chars
\B Match not at \b boundary.


\a Bell \u0007
\b Word boundary
t Tab
\r Carriage return
\v Vertical tab
\f Form feed
\n New line
\e Escape
\Oxxx Octal character xxx
\xhh Hex character hh
\cX Control char X
\uuuu Unicode character uuuu
. Any character
[aeiou] Any single char in set of chars
[^aeiou] Any single char not in set
[0-9a-fA-F] Hyphen for ranges of chars
\p{name} Any char in named char class
\P{name} Any char not in named char class
\w Any word char
\W Any non-word char
\s Any white-space char
\S Any non-white-space char
\d Any decimal digit
\D Any non-digit


( ) Captures matched substring
(?<name> ) Captures matched substring into named group
(?<name1-name2> ) Balancing group definition
(?: ) Noncapturing group
(?imnsx-imnsx: ) Applies or disables options in subexpression
(?= ) Zero-width positive lookahead assertion
(?! ) Zero-width negative lookahead assertion
(?<= ) Zero-width positive lookbehind assertion
(?<! ) Zero-width negative lookbehind assertion
(?> ) Nonbacktracking subexpression


^ $ ( ) < > [ { \ | . * + ? Must be escaped.
| Match any one of terms separated by '|'
(?(expression)yes|no) Match "yes" part if expression matches; otherwise, matches optional "no" part
(?(name)yes|no) Matches "yes" part if named capture has match; else matches optional "no" part
\number Backreference to group by number
\k<name> Backreference to named group
(?imnsx-imnsx) Sets/disables options in middle of pattern
(?# ) Inline comment
# [to end of line] X-mode comment


IgnoreCase Use case-insensitive matching.
Multiline Use multiline mode, where ^ and $ match the beginning and end of each line.
Singleline Use single-line mode, where the period (.) matches every character (instead of every character except \n).
IgnorePatternWhitespace Exclude unescaped white space from the pattern, and enable comments after a number sign (#).
ExplicitCapture Do not capture unnamed groups.
RightToLeft Search moves from right to left instead of from left to right.
ECMAScript Enable ECMAScript-compliant behavior for the expression.
CultureInvariant Zero-width positive lookbehind assertion


.NET Regex is developed by Charles Cook. Please send any feedback or suggestions to charlescook@cookcomputing.com.