Use Common Regular Expressions

Problem

You need to create a regular expression to use with validation, text searching, or text replacement (see recipes Validate Input with a Regular Expression to Replace All Occurrences of a Pattern in a String).

Solution

Use the regular expression engine provided in .NET through the types in the System.Text.RegularExpressions namespace.

Discussion

Regular expressions are a platform-independent syntax for describing patterns in text. What makes regular expressions particularly useful are their rich set of wildcards. For example, you can use ordinary String methods to find a series of specific characters (such as the word "hello") in a string. Using a regular expression, however, you can find any word in a string that ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.