Ajax software
Free javascripts
↑
Main Page
?
How to match characters that can occur an unbounded number of times, whether the characters
of interest are optional or required
?
How to match characters that can occur a specified number of times
First, look at the simplest situation: matching single characters.
Matching Single Characters
The simplest regular expression involves matching a single character. If you want to match a single,
specified alphabetic character or numeric digit, you simply use a pattern that consists of that character
or digit. So, for example, to match the uppercase letter
L
, you would use the following pattern:
L
The pattern matches any occurrence of the uppercase
L
. You have not qualified the pattern in any way to
limit matching, so expect it to match any occurrence of uppercase
L
. Of course, if matching is being carried
out in a case-insensitive manner, both uppercase
L
and lowercase
l
will be matched.
Matching a Single Character
You can apply this pattern to the sample document
UpperL.txt
, which is shown here:
Excel had XLM macros. They were replaced by Visual Basic for Applications in later
versions of the spreadsheet software.
CMLIII
Leoni could swim like a fish.
Legal difficulties plagued the Clinton administration. Lewinski was the source of
some of the former president’s difficulties.
1.
Open OpenOffice.org Writer, and open the file
UpperL.txt
.
2.
Use the Ctrl+F keyboard shortcut to open the Find And Replace dialog box, and check the
Regular Expressions check box and the Match Case check box in the Options section.
3.
Enter the regular expression pattern
L
in the Search For text box at the top of the Find And
Replace dialog box, and click the Find All button.
If all has gone well, each occurrence of an uppercase
L
should be highlighted.
Figure A-1 shows the matching of the pattern
L
in OpenOffice.org Writer against the sample document
UpperL.txt
. Notice that there are five matches contained in the sequences of characters
XLM
,
CMLIII
,
Leoni
,
Legal
, and
Lewinski
.
312
Appendix A: Simple Regular Expressions
bapp01.qxd:bapp01 10:47 312
Ajax software
Free javascripts
→