JavaScript Editor Ajax software     Free javascripts 



Main Page

To look for lines that contain matches for
colour
and
color
using the
findstr
utility, enter the following
at the command line:
findstr /N colo*r Colors.txt
The preceding command line assumes that the file
Colors.txt
is in the current directory.
Figure A-15 shows the result from using the
findstr
utility on
Colors.txt
.
Notice that lines that contain the sequences of characters
color
and
colour
are successfully matched,
whether as whole words or parts of longer words. However, notice, too, that the slightly strange “word”
colouuuurful
is also matched due to the
*
metacharacter’s allowing multiple occurrences of the lower-
case letter
u
. In most practical situations, such bizarre “words” won’t be an issue for you, and the
*
quanti-
fier will be an appropriate substitute for the
?
quantifier when using the
findstr
utility. In some situations,
where you want to match precisely zero or one specific characters, the
findstr
utility may not provide
the functionality that you need, because it would also match a character sequence such as
colonifier
.
Figure A-15
Having seen how you can use a single optional character in a regular expression pattern, take a look at
how you can use multiple optional characters in a single regular expression pattern.
Matching Multiple Optional Characters
Many English words have multiple forms. Sometimes, it may be necessary to match all of the forms of
a word. Matching all those forms can require using multiple optional characters in a regular expression
pattern.
Consider the various forms of the word
color
(U.S. English) and
colour
(British English). They include
the following:
color (U.S. English, singular noun)
colour (British English, singular noun)
colors (U.S. English, plural noun)
328
Appendix A: Simple Regular Expressions
bapp01.qxd:bapp01 10:47 328


JavaScript Editor Ajax software     Free javascripts