O'Reilly logo

C# 5.0 Programmer's Reference by Rod Stephens

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 T Regular Expressions

This appendix summarizes methods of creating and using regular expressions.

Creating Regular Expressions

This section describes the characters you can use to define regular expressions.

Character Escapes

Character escapes are character sequences that match special characters. The following table summarizes useful character escapes.

EscapeMeaning
\tMatches the tab character
\rMatches the return character
\nMatches the new-line character
\nnnMatches a character with ASCII code given by the two or three octal digits nnn
\xnnMatches a character with ASCII code given by the two hexadecimal digits nn
\unnnnMatches a character with Unicode representation given by the four hexadecimal digits nnnn

Character Classes

A character class matches one of a set of characters. The following table summarizes useful character class constructs.

ConstructMeaning
[chars]Matches one of the characters inside the brackets. For example, [aeiou] matches a single lowercase vowel.
[^chars]Matches a character that is not inside the brackets. For example, [^aeiouAEIOU] matches a single nonvowel character such as Q, ?, or 3.
[first-last]Matches a character between the character first and the character last. For example, [a–z] matches any lowercase letter between a and z. You can combine multiple ranges as in [a-zA-Z], which matches uppercase or lowercase letters.
.This is a wildcard that matches any single character except \n. (To match a period, use the

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