How to Use Matching

The most basic use of regular expressions is that of matching substrings within a string. Matching can be for words, characters, or any other conceivable sequence required. For example, given the string "Angie called Albert" we could begin by locating the capital letter A only if it begins a word. The following regular expression would do just that:

\bA

Translated, it means “begin on a word boundary and find the letter A.” The matches produced would be two matches for the letter A: the first letter of Angie and Albert. No other characters would be included in the match result. We could extend this pattern to locate all words that begin with the letter A. The regular expression to accomplish this would be as follows:

 \bA\w+ ...

Get Microsoft® Visual C#® .NET 2003 Unleashed 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.