[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Understand C# regular expression symbols

The following table shows useful regular expression symbols, commands, and other items that you can use in regular expressions in C# programs.

Item Purpose
\ Either begins a special symbol such as \n or escapes the following character
^ Matches the beginning of string (or line if in multiline mode)
$ Matches the end of string (or line if in multiline mode)
\A Matches the beginning of string (even if in multiline mode)
\Z Matches the end of string (even if in multiline mode)
* Matches the preceding character zero or more times
+ Matches the preceding character one or more times
? Matches the preceding character zero or one time
. Matches any character
[abc] Matches any one of the characters inside the brackets
[^abc] Matches one character that is not inside the brackets
[a-z] Matches one character in the range of characters
[^a-z] Matches one character that is not in the range of characters
x|y Matches x or y
(pattern) Makes a match group
(?<name>pattern) Makes a match group and gives it a name
\n Refers to a previously defined group
(?:pattern) Make a non-capturing group (a group that you can't later refer to)
{n} Matches exactly n occurrences
{n,} Matches n or more occurrences
{n,m} Matches between n and m occurrences
(?=...) Positive lookahead (must match the pattern at this point)
(?!...) Negative lookahead (must not match the pattern at this point)
(?<=...) Positive lookbehind (the preceding text must match the pattern)
(?<!--...) Negative lookbehind (the preceding text must not match the pattern)
\b Matches a word boundary
\B Matches a non-word boundary
\d Matches a digit
\D Matches a non-digit
\f Matches a form-feed
\n Matches a newline
\r Matches a carriage return
\s Matches white space (space, tab, form-feed, etc.)
\S Matches non-white space
\t Matches a tab
\v Matches a vertical tab
\w Matches a word character (includes underscore)
\W Matches a non-word character

Note that the regular expressions used by .NET are not exactly the same as those used by some other programming languages. If you're searching the internet for regular expression information, be sure you're looking at a .NET friendly version or you could get pretty confused.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.