This section contains code examples that illustrate the use of regular expressions in common applications.
The System.Web.RegularExpressions namespace contains a number of regular expression objects that implement predefined regular expression patterns for parsing strings from HTML, XML, and ASP.NET documents. For example, the TagRegex class identifies start tags in a string and the CommentRegex class identifies ASP.NET comments in a string.
Provides an example that searches an input string and prints out all the href="…" values and their locations in the string.
Provides an example that replaces dates in the form mm/dd/yy with dates in the form dd-mm-yy.
Provides an example that extracts a protocol and port number from a string that contains a URL. For example, "http://www.contoso.com:8080/letters/readme.html" returns "http:8080".
Provides an example that strips invalid non-alphanumeric characters from a string.
Provides an example that you can use to verify that a string is in valid e-mail format.
Provides class library reference information for the .NET Framework System.Text.RegularExpressions namespace.
Provides an overview of the programming language aspect of regular expressions.
Describes the regular expression classes contained in the System.Text.RegularExpression namespace and provides examples of their use.
Provides information about the capabilities and behavior of .NET Framework regular expressions.
Provides information on the set of characters, operators, and constructs that you can use to define regular expressions.
Would you guys with the earlier comments be happier with the text "links to examples" ?
This is a typical problem in MSDN. They seem to think that no-one will read their pages if they have more than a handfull of lines, so they have a page with links that links to a page with links and those links in turn link to another page with links. Finally at the bottom of the chain the examples tend out not to be worth having because again they are thinking in terms of web pages and not in terms of documents and don't want to make the examples too long.
I just want a single and comprehensive (and long) page that I can print out and read. Note - MSDN people - that I don't want a page that will only print properly in letter format either !!
Personally, I'd prefer to have a page with decent examples/samples.
For many, Regular Expressions are very hard to grok (although once you get in to it, they're not TOO bad). Examples on a page titled "Regular Expression Examples" would seem to be a good thing.
Matches (as I understand it) are by default greed, that is they will match as much as they can of the string. Sometimes you want the smallest match.
(PowerShell Example)PS> $line = "one apple, two oranges, three pears, four pineapples"
PS>#Example of a greedy regular expression (largest possible match)PS> $line -replace "\s.+,\s", "REPLACED"oneREPLACED four pineapples
PS>#Example of lazy match (by using ? to force lazy match)PS> $line -replace "\s.+?,\s", "REPLACED"oneREPLACEDtwoREPLACEDthreeREPLACEDfour pineapples
More examples at:
http://en.wikipedia.org/wiki/Regular_expressions#Lazy_quantification