Previous slide Next slide Back to the first slide View text version


Notes:

This example illustrates the use of the asterisk character two match an expression zero or more times.

In the first example, the expression wants to match a space; followed by an uppercase or lowercase V. The next character will any lowercase alpha character. However, with the asterisk immediately after the closing square bracket, the single alpha character range can occur zero or more times. This match can take place anywhere within the record. Based upon how the complete expression is defined, the string “ V “ or “ v “ (a v character surrounded by spaces) could satisfy this match. When using this expression with the fortunes file, lines 1, 9, and 13 satisfies the pattern match.

In the second example, the expression defined will result in lines 1, 9, and 13 to satisfy the match as the expression wants to match a space; followed by an uppercase or lowercase V. The subexpression, [a-z]*, specifies a single lowercase alpha character that can occur zero or more times; followed by any printable character; and finally a space. By including the period (to match any printable character), line 8 now satisfies the expression. This is because the expression [a-z]* occurred one time (satisfying the interpretation of the asterisk character); and the period (match any character) happens to match up with the period character. In this example, the string that matched the expression is underlined.