A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://www.wellho.net/regex/dotnet.html below:

Regular Expressions in Visual Basic, C++ and C# under .NET

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))


 • This site uses cookies - see [here] for details.
 • If you proceed, we will take that as your consent to accept cookies

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 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

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}?" ?

[#3563]

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

Average page ranking - 4.0

© WELL HOUSE CONSULTANTS LTD., 2025: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: +44 (0)1225 708225 • FAX: +44 (0)1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4