Ajax software
Free javascripts
↑
Main Page
Figure A-16
As you can see, all the sample forms of the word of interest have been matched.
This description focuses initially on matching of the forms of the word
colour
/
color
.
How does the pattern
colou?r’?s?’?
match the word
color
? Assume that the regular expression
engine is at the position immediately before the first letter of
color
. It first attempts to match lower-
case
c
, because one lowercase
c
must be matched. That matches. Attempts are then made to match a
subsequent lowercase
o
,
l
, and
o
. These all also match. Then an attempt is made to match an optional
lowercase
u
. In other words, zero or one occurrences of the lowercase character
u
is needed. Because
there are zero occurrences of lowercase
u
, there is a match. Next, an attempt is made to match lower-
case
r
. The lowercase
r
in
color
matches. Then an attempt is made to match an optional apostrophe.
Because there is no occurrence of an apostrophe, there is a match. Next, the regular expression engine
330
Appendix A: Simple Regular Expressions
bapp01.qxd:bapp01 10:47 330
Ajax software
Free javascripts
→