Regular Expressions 4/4
In addition, there are some predefined expressions for whole classes of characters, as
shown in Table 2:
Table 2: Regex character classes in TextPad and BBEdit
[:alpha:] Any alphabetical character
[:lower:] Any lowecase alphabetical character
[:upper:] Any uppercase alphabetical character
[:alnum:] \w Any alphanumeric character
[:word:] Any alphanumeric character, hyphen, and apostrophe
\W Any character (including whitespace) except alphanumeric characters
[:digit:] \d or # Any numerical character
\D Any character except alphanumeric characters
[:blank:] Space or tab
[:space:] \s Any whitespace character
[:graph:] \S Any character except whitespace characters
[:punct:] Any character except alphanumeric and whitespace characters
4. EXERCISES
1. For each of the following adjectives, design a regex pattern that will retrieve
all of its forms.
TALL (tall, taller, tallest) FIT (fit, fitter, fittest)
NICE (nice, nicer, nicest) SCARY (scary, scarier, scariest)
2. For each of the following nouns, design a regex pattern that will retrieve all of
its forms:
BOOK (book, books) CHILD (child, children)
BUS (bus, buses) LEAF (leaf, leaves)
WOMAN (woman, women) MOUSE (mouse, mice)
3. For each of the following verbs, design at least one regex pattern that will
retrieve all of its forms:
WALK (walk, walks, walking, walked)
HIT (hit, hits, hitting)
FLIP (flip, flips, flipping, flipped)
SIT (sit, sits, sitting, sat)
STEAL (steal, steals, stealing, stole, stolen)
FIND (find, finds, finding, found)
SING (sing, sings, singing, sang, sung)
TAKE (take, takes, taking, took, taken)
FLY (fly, flies, flying, flew, flown)
WREAK (wreaks, wreaked, wrought, wreaking)
Ger. SPRINGEN (spring, springe, springst, springt, springen, sprang, sprangst,
sprangt, sprangen, gesprungen)
4. Use TextPad or BBEdit to search a 1-million word corpus (like BROWN,
FROWN, LOB, FROB, etc.) for some of the patterns you have designed.