The website http://regexpal.com/
allows you to test regular expressions on sample text. We will use the page in the steps below. Enter regular expressions in the top box and sample text in the bottom box.
Ahab was born in 1802. Starbuck, in '98 --- 1998, that is. And (as everyone knows), Ishmael was born in 2036 but died in 1879 (making him [1879-2036=]-57 years old at the time of his death, or 48, depending on how you count). And the white whale was immortal.
Am I telling this story right? Anyhow, each of them had access to a time machine, a harpoon, and 20+ sheep for barter. Including the whale. As was common in his era, Starbuck had his own name tattooed on the back of his arm: "*$", it read, "Star-buck", a kind of pun.
Our story begins in interstellar space, in the year 2000 BC...
\w
does? What do you think the +
sign does?
\s
does?
b
, f
, or m
. Note: you may need to match the whitespace before the word as well.\n
is a special character that denotes a line break. Find an expression that matches all the words that appear at the end of a line. Keep in mind that the words at the end of the line may have punctuation before the linebreak that you will need to match.\d
does.Download ACT3-1.py
and poem.txt
in the same directory, then open ACT3-1.py
with IDLE. (Remember why we need to put poem.txt
in the same directory as the Python program?). Press F5.
myStr = readShel() printRegex('g\w+', myStr) printRegex('\sg\w+', myStr) printRegex('\s[gG]\w+', myStr) printRegex('out', myStr) printRegex('\wout', myStr) printRegex('\w+out', myStr) printRegex('[\s\w]out', myStr)
it
.it
. A word should be surrounded by whitespace. There are five instances of the word it
.it
, followed by at least one other letter. There are six such matches.ings
. Hint: There are only two words, and they are both followed by punctuation.She'd
and I'll
), but write the expression to return any contraction.