O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required