3.5 Useful Applications of Regular Expressions

Doing More with Word Pieces
Once we can use re.findall() to extract material from words, there are interesting
things to do with the pieces, such as glue them back together or plot them.
It is sometimes noted that English text is highly redundant, and it is still easy to read
when word-internal vowels are left out. For example, declaration becomes dclrtn, and
inalienable becomes inlnble, retaining any initial or final vowel sequences. The regular
expression in our next example matches initial vowel sequences, final vowel sequences,
and all consonants; everything else is ignored. This three-way disjunction is processed
left-to-right, and if one of the three parts matches the word, any later parts of the regular
expression are ignored. We use re.findall() to extract all the matching pieces, and
”.join() to join them together.

Leave a Reply