Notice that the
metacharacter differs significantly in meaning from the literal characters used in pat-
terns so far. The character
in a pattern could match only an uppercase L, but the metacharacter
of the numeric digits
A metacharacter often matches a
of characters. In this case, the metacharacter
matches the class
of characters that are numeric digits.
When you have the pattern
, you know that it matches three successive numeric digits, but it will
and hundreds of other numbers.
Matching Triple Numeric Digits
Suppose that you want to match a sequence of three numeric digits. In plain English, you might say that you
want to match a three-digit number. A slightly more formal way to express what you want to do is this: Match
a numeric digit. If the first character is a numeric digit, attempt to match the next character as a numeric digit.
If both the characters are numeric digits, attempt to match a third successive numeric digit.
matches a single numeric digit; therefore, as described a little earlier, you could use
to match three successive numeric digits.
If all three matches are successful, a match for the regular expression pattern has been found.
The test file,
, is shown here:
Part Number DRC22
Part Number XFA221
Part Number RRG417
For the moment, aim to match only the numeric digits using the pattern
Navigate to the directory that contains the file
in a web browser.
Click the button labeled Click Here To Enter Text.
When the prompt box opens, enter a string to test. Enter a string copied from
Click the OK button and inspect the alert box to see if the string that you entered contained a
match for the pattern
Figure A-7 shows the result after entering the string Part Number
Appendix A: Simple Regular Expressions
bapp01.qxd:bapp01 10:47 320