Click to Rate and Give Feedback

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Developer's Guide
Regular Expression Language Elements

The Windows Software Development Kit (SDK) provides an extensive set of regular expression tools that enable you to efficiently create, compare, and modify strings as well as rapidly parse large amounts of text and data to search for, remove, and replace text patterns.

This section details the set of characters, operators, and constructs that you can use to define regular expressions.

Character Escapes

Provides information on the set of escape characters that signal to the regular expression parser that the character is not an operator and should be interpreted as a matching character.

Substitutions

Provides information on the special constructs used in replacement patterns.

Character Classes

Provides information on the set of regular expression characters that define the substring to match.

Regular Expression Options

Provides information on the set of options that modify a regular expression pattern's matching behavior.

Atomic Zero-Width Assertions

Provides information on zero-width assertions that cause a match to succeed or fail depending on the regular expression parser's current position in the input string.

Quantifiers

Provides information on optional quantity data that modify a regular expression.

Grouping Constructs

Provides information on grouping constructs that cause a regular expression to capture groups of subexpressions.

Backreference Constructs

Provides information on regular expression backreference modifiers.

Alternation Constructs

Provides information on alternation information that modifies a regular expression to allow either/or matching.

Miscellaneous Constructs

Provides information on miscellaneous constructs that modify regular expression matching behavior.

System.Text.RegularExpressions Namespace

Provides class library reference information for the .NET Framework System.Text.RegularExpressions namespace.

.NET Framework Regular Expressions

Provides a brief introduction to .NET regular expressions.

Regular Expressions as a Language

Provides an overview of the programming language aspect of regular expressions.

Regular Expression Classes

Provides detailed information and code examples illustrating how to use the regular expression classes.

Details of Regular Expression Behavior

Provides detailed information about the capabilities and behavior of .NET Framework regular expressions.

Regular Expression Examples

Provides code examples illustrating typical uses of regular expressions.

Community Content   What is Community Content?
Add new content RSS  Annotations
quick reference, please      exotericist ... Noelle Mallory - MSFT   |   Edit   |   Show History

could you provide a link to a quick reference page here, please?

i'm looking for the whitespace signifier and i can't find it.

the grouped pages are very, um, ordered (yay, geekout!) but pretty much useless if you don't know what category of element you're looking for.

Quick reference      Cheeser   |   Edit   |   Show History
I second the request to have a quick reference of regular expression elements, maybe even a printable cheat sheet?
I concur      calandale   |   Edit   |   Show History
But, unfortunately, the documentation is seldom set up to be less than useful, in general.

The cheatsheet we desire exists, by following all the links of this page. Wouldn't it be nice

if there was a way to print it all out, rather than having to do it one link at a time?


The Cheat Sheet      OuTa-SyNc   |   Edit   |   Show History
Tags What's this?: Add a tag
Flag as ContentBug
Weird behaviour regular expression      Jaap K   |   Edit   |   Show History
I met the following strange behaviour using regular expressions. Can somebody explain?

I use expression ^([\w][^\.\\/])+(.xls){1}$ to catch invalid filenames: . \ or / are not wanted.

Some learned the following:
* VALID = excellfile.xls, excellexport.xls, excell.xls
* NOT VALID = excelfile.xls, excelexport.xls, excel.xls

Somehow it appears that the text excel is not excepted.

Tags What's this?: Add a tag
Flag as ContentBug
Your expression is wrong      CLovegren   |   Edit   |   Show History
Jaap, the expression you provided tells the pattern matching engine to find a single "word" character, followed by anything but a ., \, or /. You then tell the engine to match these at least once, and, once it's found all that it can, it then must match .xls once and only once and that the .xls must be at the end of the string.

1) your matching pattern is two characters wide, \w & [^\.\\/], both of these must pass every time for your ()+ to work. All of your file names are of odd lengths, this will never work.
2) you tell it that the second character in the match must not be ., \, or /. As the ending works it's way down the string, it will eventually encounter a ., but you told the pattern that a dot is not acceptable, this causes the match to fail and the pattern unwinds to the last successful match. You the tell it that it must be followed by .xls, but when it unwinds, it goes back to the start of the last attempted match, which, in your examples, would be 'e.xls', 't.xls', and 'l.xls' respectively.
3) lastly, and this isn't causing failures, you match against (.xls){1}$, the {1} is unnecessary as every pattern will match only once unless you alter the match pattern with {}, ?, +, *, etc.

^([^\.\\/])+(.xls)$

This tells the engine to match everything except for ., \, and / as many times as possible (and at least once) starting from the beginning of the string, once it's exhausted all that it can, it must be followed by .xls which must also be at the end of the line.

http://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1236361993&sr=8-1

Tags What's this?: Add a tag
Flag as ContentBug
Your expression is wrong too :)      caius jard   |   Edit   |   Show History
CLovegren, I'm not 100% sure that the . in your (.xls) will lose its "any character" meaning, and hence allow excelfile!xls, excelfile/xls etc
Note also that a . in a character class [ ] loses "any character" meaning. Hence I propose that the following regex would be correct for ensuring that a filename was (any character other than dot slash backslash) followed by ".xls":

^[^./\\]+[.]xls$
Tags What's this?: Add a tag
Flag as ContentBug
muchas gracias, OuTa-SyNc      jumpin jack flash ... Thomas Lee   |   Edit   |   Show History
Several months on, and no one's even said thanks (See post #4 in Oct 2008)! Let me be the first, OuTa-SyNc.

You've just saved me hours of cutting, pasting, making SIMPLE examples (someone should run a course on that at Redmond) and reformatting, plus you've introduced a new resource: RegExLib.com.

Many thanks, OuTa-SyNc, and Hats off to you.
Tags What's this?: regex (x) Add a tag
Flag as ContentBug
quick reference, cheat sheet and then some      jumpin jack flash   |   Edit   |   Show History
And there's icing on the cake, too. That new resource http://regexlib.com has a list http://regexlib.com/Resources.aspx of 15 electronic and 6 paper titles ranging from online testing tools to Java, .NET and Oracle reference books.

One outstanding entry aspires to become the best .NET regular expression development tool on the planet, offering a regex-creation gui featuring
    • a 30-minute tutorial, with simple, one-topic examples, suitable for idiots like me
    • tree-structured analysis
    • highlighting of matches
    • testing of full expressions, highlighted portion and unhighlighted portion
    • Visual Basic, C#, or Managed C++ code-creation
    • an (apparently customizable) expression-library

and more.
A look at Expresso 3.0 from http://www.ultrapico.com/Expresso.htm should be well worth the time spent.

Tags What's this?: regex (x) Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker