Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
One of the most common regular expression operators is a
quantifier. ? is a quantifier that matches the preceding
item 0 or 1 time. In other words, ?
means optional. An item is either a single character
or a complex structure of characters in square brackets. For example, the
regular expression "colou?r" matches
color and colour, but not colouur:
Console.WriteLine (Regex.Match ("color", @"colou?r").Success); // True
Console.WriteLine (Regex.Match ("colour", @"colou?r").Success); // True
Console.WriteLine (Regex.Match ("colouur", @"colou?r").Success); // False
Regex.Match searches within a
larger string. The object that it returns has properties for the Index and Length of the match, as well as the actual
Value matched: