Appendix B. Regular Expressions

The following tables summarize the regular expression grammar and syntax supported by the regular expression classes in System.Text.RegularExpressions. 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).

All the syntax described in Table B-1 through Table B-10 should match the Perl5 syntax, with specific exceptions noted.

Table B-1. Character escapes

Escape Code Sequence


Hexadecimal equivalent








Carriage return


Vertical tab


Form feed






ASCII character as octal


ASCII character as hex


ASCII control character


Unicode character as hex


A nonescape character

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

Table B-2. Substitutions




Substitutes last substring matched by group-number


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


Substitutes a literal “$”


Substitutes copy of the entire match


Substitutes text of the input string preceding match


Substitutes text of the input string following match


Substitutes the last captures group


Substitutes the entire input string

Substitutions are specified only ...

Get C# Essentials, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.