Visual Basic, C++ and C# amongst other languages can make use of the shared regular expression library provided under Microsoft's .NET framework. The library is uses Perl-flavoured regular expressions, but with some subtle variations.
Operator Type | Examples | Description |
Literal Characters Match a character exactly |
a A y 6 % @ | Letters, digits and many special
characters match exactly |
\$ \^ \+ \\ \? | Precede other special characters
with a \ to cancel their regex special meaning |
\n \t \r | Literal new line, tab, return |
\cJ \cG | Control codes |
\xa3 | Hex codes for any character |
\u00a3 | Unicode for any character |
Anchors and assertions |
^ | Starts with |
$ | Ends with |
\b \B | on a word boundary, NOT on a word boundary |
Character groups any 1 character from the group |
[aAeEiou] | any character listed from [ to ] |
[^aAeEiou] | any character except aAeEio or u |
[a-fA-F0-9] | any hex character (0 to 9 or a to f) |
. | any character at all (not new line in some circumstances) |
\s | any space character (space \n \r or \t) |
\w | any word character (letter digit or _) |
\d | any digit (0 through 9) |
\S \W \D | any character that is NOT a space word character or digit |
Counts apply to previous element |
+ | 1 or more ("some") |
* | 0 or more ("perhaps some") |
? | 0 or 1 ("perhaps a") |
{4} | exactly 4 |
{4,} | 4 or more |
{4,8} | between 4 and 8 |
Add a ? after any count to turn it sparse (match as
few as possible) rather than have it default to greedy |
Alternation |
| | either, or |
Grouping |
( ) | group for count and save to variable |
(?: ) | group for count but do not save |
Option modes can be specified as using a (?x ) if you wish them to
cover part of the regular expression, or as per the following table if you
want them to apply to the whole of a regular expression:
Option | Description |
.IgnoreCase | Ignore case in matching |
.IgnorePatternWhiteSpace | White space is to be treated as a comment (otherwise it
matches exactly) |
.Singleline | . to match everything including new line (otherwise it
matches everything except new line) |
.Multiline | ^ and $ to match embedded new lines |