JavaScript Editor Ajax software     Free javascripts 



Main Page

Figure A-18
As you can see, the only change from the result of using the pattern
ABC[0-9]*
is that the pattern
ABC[0-9]+
fails to match the part number
ABC
.
When the regular expression engine is at the position immediately before the uppercase
A
of the part
number
ABC
, it attempts to match an uppercase
A
. That matches. Next, subsequent attempts are made
to match an uppercase
B
and an uppercase
C
. They too match. At that stage, the first three characters
in the regular expression pattern have been matched. Finally, an attempt is made to match the pattern
[0-9]+
, which means “Match one or more numeric characters.” There are zero numeric digits follow-
ing the uppercase
C
. Because there are exactly zero numeric digits after the uppercase
C
of
ABC
, there is
no match (zero numeric digits fails to match the criterion “one or more numeric digits,” specified by the
+
quantifier). Because the final component of the pattern fails to match, the whole pattern fails to match.
Why does the part number
ABC8899
match? When the regular expression engine is at the position imme-
diately before the
A
of
ABC8899
, it attempts to match the next character in the part number with an upper-
case
A
. Because the first character of the part number
ABC8899
is an uppercase
A
, there is a match. Next,
335
Appendix A: Simple Regular Expressions
bapp01.qxd:bapp01 10:47 335


JavaScript Editor Ajax software     Free javascripts