Reasoning about Code
Regular Expression Crossword Puzzle
Regex Questions
Start by snarfing the code from the class website. Alternatively, you can browse code here.
Think about the following pieces of code and try them on paper rather than simply typing them into the interpreter. After your group is confident in its answer, try your regular expression on a list of dictionary words using the program you downloaded.
- What five letter words end with the letter 'd'?
\w{4}d$ - The regular expression [aeiou]$ indicates there are 6988 words that end in a vowel. What words start and end with a vowel?
^[aeiou]\w*[aeiou]$
- What words start and end with the same vowel, like amoeba?
^([aeiou])\w*\1$
- The words obsequious and pharmacopoeia each
contain four vowels in a row. What words contain four consecutive vowels?
- The word maintaining contains the
two letter sequence "in" repeated three times — in genomics this
could be called a triple-repeat. What words contain the two letter sequence "in" repeated three times (letters may appear between the repeats)?
- The word contentment contains the two letter sequence
"nt" repeated three times. What words contain some two
letter sequence repeated three times? For example, both
contentment and maintaining are among such words (letters may appear between the repeats).
- The word interpreter contains the two letter sequence
"er" followed by the sequence reversed "re" followed by the original
two letter sequence "er". What words contain some two
letter sequence followed by the sequence reversed followed by the
original sequence (letters may appear between the repeats)?
- You may have seen the word puzzle "what English word contains
three doubled-letters in a row?" to which the answer is "bookkeeper"
with double-o, double-k, double-e in a row. If we allow letters to
appear between the doubled-letters we get more words, like
unsuccessfully which has a double-c, double-s, and
double-l. What words contain three doubled letters
appearing anywhere in the word, not necessarily adjacent to each
other?
- The regular expression ((\w)\w\2)\w*\1 matches the 12 words
below (and only these words). Explain why these words match, how the
regular expression works. Note that the expression (\w) is the
second tagged expression since the first left parenthesis begins the
first tagged expression — you count tagged expressions by the order in
which the left-parenthesis appears in reading left-to-right.
amalgamate amalgamated amalgamates amalgamatating amalgamatation assesses dereference monotonous monotonously monotonousness possesses sensitivities
- The regular expression ((\w)\w\2){3} matches the two words
below (and only these two words). Explain why these words match, i.e., how
the regular expression works.
agamemnon precipitateness
Write a word-puzzle question for the lab section to answer (you must have a solved it first!). We will pose your puzzles to the class as the last part of this lab.