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
, you would use the following pattern:
The pattern matches any occurrence of the uppercase
. You have not qualified the pattern in any way to
limit matching, so expect it to match any occurrence of uppercase
. Of course, if matching is being carried
out in a case-insensitive manner, both uppercase
will be matched.
Matching a Single Character
You can apply this pattern to the sample document
, which is shown here:
Excel had XLM macros. They were replaced by Visual Basic for Applications in later
versions of the spreadsheet software.
Leoni could swim like a fish.
Legal difficulties plagued the Clinton administration. Lewinski was the source of
some of the former president’s difficulties.
Open OpenOffice.org Writer, and open the file
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.
Enter the regular expression pattern
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
should be highlighted.
Figure A-1 shows the matching of the pattern
in OpenOffice.org Writer against the sample document
. Notice that there are five matches contained in the sequences of characters
Appendix A: Simple Regular Expressions
bapp01.qxd:bapp01 10:47 312