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:


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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.