O'Reilly logo

C# Essentials by Peter Drayton, Ben Albahari, Brad Merrill

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix B. Regular Expressions

The following tables summarize the regular-expression grammar and syntax supported by the regular-expression classes in System.Text. RegularExpression. Each of the modifiers and qualifiers in the tables can substantially change the behavior of the matching and searching patterns. For further information on regular expressions, we recommend the definitive Mastering Regular Expressions by Jeffrey E. F. Friedl (O’Reilly & Associates).

All the syntax described in the tables should match the Perl5 syntax, with specific exceptions noted.

Table B-1. Character Escapes

Escape Code Sequence

Meaning

Hexadecimal Equivalent

\a

Bell

\u0007
\b

Backspace

\u0008
\t

Tab

\u0009
\r

Carriage return

\u000A
\v

Vertical tab

\u000B
\f

Form feed

\u000C
\n

Newline

\u000D
\e

Escape

\u001B
\040

ASCII character as octal

 
\x20

ASCII character as hex

 
\cC

ASCII control character

 
\u0020

Unicode character as hex

 
\non-escape

A nonescape character

 

Special case: within a regular expression, \b means word boundary, except in a [] set, where \b means the backspace character.

Table B-2. Substitutions

Expression

Meaning

$group-number

Substitutes last substring matched by group-number

${group-name}

Substitutes last substring matched by (?< group-name >)

Substitutions are specified only within a replacement pattern.

Table B-3. Character Sets

Expression

Meaning

.

Matches any character except \n

[characterlist]

Matches a single character in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required