Many linguistic processing tasks involve pattern matching. For example, we can find
words ending with ed using endswith(‘ed’). Regular expressions give us a more powerful and flexible method for de
scribing the character patterns we are interested in.
There are many other published introductions to regular expressions,
organized around the syntax of regular expressions and applied to
searching text files. Instead of doing this again, we focus on the use of
regular expressions at different stages of linguistic processing. As usual,
we’ll adopt a problem-based approach and present new features only as
they are needed to solve practical problems. In our discussion we will
mark regular expressions using chevrons like this: «patt». To use regular expressions in Python, we need to import the re library using: import
re. We also need a list of words to search; we’ll use the Words Corpus again. We will preprocess it to remove any proper names.
import re
wordlist = [w for w in nltk.corpus.words.words(‘en’) if w.islower()]
