Ajax software
Free javascripts
↑
Main Page
Figure A-6
These two examples have shown how you can match doubled characters using one of the syntax options
that are available. Later in this appendix, you will look at an alternative syntax that can match an exact
number of successive occurrences of a desired character, which can be exactly two or can be a larger num-
ber. The alternative syntax uses curly braces and, in addition to allowing matches of an exact number of
occurrences, allows variable numbers of occurrences to be matched.
Introducing Metacharacters
To match three characters, you can simply write the character three times in a row to form a pattern. For
example, to match part numbers that take the form
ABC123
(in other words, three alphabetic characters
followed by three numeric digits, which will match the alphabetic characters
AAA
), simply use the fol-
lowing pattern:
AAA
To match the other part of such part numbers, you need to introduce the concept of a
metacharacter
. The
patterns you have seen so far include characters that stand, literally, for the same character. A metachar-
acter can be a single character or a pair of characters (the first is typically a backslash) that has a meaning
other than the literal characters it contains.
There are several ways in which you can match the
123
part of a part number of the form
ABC123
. One
is to write the following:
\d\d\d
Each
\d
is a metacharacter that stands for a numeric digit 0 through 9, inclusive. The
\d
metacharacter
does
not
stand for a backslash followed by a lowercase
d
.
319
Appendix A: Simple Regular Expressions
bapp01.qxd:bapp01 10:47 319
Ajax software
Free javascripts
→