colours (British English, plural noun)
color’s (U.S. English, possessive singular)
colour’s (British English, possessive singular)
colors’ (U.S. English, possessive plural)
colours’ (British English, possessive plural)
The following regular expression pattern, which includes three optional characters, can match all eight
of these word forms:
If you tried to express this in a semiformal way, you might have the following problem definition:
Match the U.S. English and British English forms of
), including the singular noun,
the plural noun, and the singular possessive and the plural possessive.
Try it out, and then I will explain why it works and what limitations it potentially has.
Matching Multiple Optional Characters
Use the sample file
to explore this example:
These colors are bright.
Some colors feel warm. Other colours feel cold.
A color’s temperature can be important in creating reaction to an image.
These colours’ temperatures are important in this discussion.
Red is a vivid colour.
To test the regular expression, follow these steps:
Open OpenOffice.org Writer, and open the file
Use the keyboard shortcut Ctrl+F to open the Find And Replace dialog box.
Check the Regular Expressions check box and the Match Case check box.
In the Search For text box, enter the regular expression pattern
, and click the Find
All button. If all has gone well, you should see the matches shown in Figure A-16.
Appendix A: Simple Regular Expressions
bapp01.qxd:bapp01 10:47 329