Training, Open Source computer languages

PerlPythonMySQLTclRubyC & C++LuaJavaTomcatPHPhttpdLinux

Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua, Tcl, C and C++ training - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, Ruby, MySQL and Linux / Tomcat systems

Regular Expressions in .NET
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 TypeExamplesDescription
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 \rLiteral new line, tab, return
\cJ \cGControl codes
\xa3Hex codes for any character
\u00a3Unicode for any character
Anchors and assertions ^Starts with
$Ends with
\b \Bon 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)
\sany space character (space \n \r or \t)
\wany word character (letter digit or _)
\dany digit (0 through 9)
\S \W \Dany character that is NOT a space
word character or digit
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:
.IgnoreCaseIgnore case in matching
.IgnorePatternWhiteSpaceWhite 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

Back to Regular Expression Home Page
Jump to Elements of a regular expression
Order a Regular Expression Mousemat for £4.95 inclusive

Comment: "Mostly excellent; however, I see these potential problems ..."
Visitor Ranking 4.0 (5=excellent, 1=poor)

Comment by Yahya Abdal-Aziz (published 2010-05-18)
Mostly excellent; however, I see these potential problems for new regex users:
1. Is space a literal character i.e. matching "[ ]" or some special character e.g. "\x" ?
2. What do you mean by "a word boundary"?
3. If counts "apply to previous element", what defines, bounds or marks an element?
4. You write: "Add a ? after any count to turn it sparse". Would that be, e.g., "{4,8?}" or "{4,8}?" ?

You can Add a comment or ranking or edit your own comments

Average page ranking - 4.0

© WELL HOUSE CONSULTANTS LTD., 2017: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho