Ajax software
Free javascripts
↑
Main Page
You will find matches on four lines, as shown in Figure A-11. The preceding command line will work
correctly only if the
ABC123.txt
file is in the current directory. If it is in a different directory, you will
need to reflect that in the path for the file that you enter at the command line.
The next section combines the techniques that you have seen so far to find a combination of literally
expressed characters and a sequence of characters.
Figure A-11
Matching Sequences of Different Characters
A common task in simple regular expressions is to find a combination of literally specified single charac-
ters plus a sequence of characters.
There is an almost infinite number of possibilities in terms of characters that you could test. This section
focuses on a very simple list of part numbers and look for part numbers with the code DOR followed by
three numeric digits. In this case, the regular expression should do the following:
Look for a match for uppercase
D
. If a match is found, check if the next character matches uppercase
O
. If
that matches, next check if the following character matches uppercase
R
. If those three matches are pres-
ent, check if the next three characters are numeric digits.
Finding Literal Characters and Sequences of Characters
The file
PartNumbers.txt
is the sample file for this example:
BEF123
RRG417
DOR234
DOR123
CCG991
First, try it in OpenOffice.org Writer, remembering that you need to use the regular expression pattern
[0-9]
instead of
\d
.
1.
Open the file
PartNumbers.txt
in OpenOffice.org Writer, and open the Find And Replace
Dialog box by pressing Ctrl+F.
2.
Check the Regular Expression check box and the Match Case check box.
3.
Enter the pattern
DOR[0-9][0-9][0-9]
in the Search For text box and click the Find All button.
324
Appendix A: Simple Regular Expressions
bapp01.qxd:bapp01 10:47 324
Ajax software
Free javascripts
→