The website http://regexpal.com/
allows you to demo 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.
nameGame()
in ACT3-2.py
to make a rhyme with your name. Copy it into the bottom box.b
, f
, or m
to your name (or the suffix of your name).\w
does? What do you think the +
sign does?
\s
does?
b
, f
, or m
.\n
is a special character that denotes a line break. Get all the words that appear at the end of a line.\d
does.Go back to ACT3-2.py
. Download and save poem.txt
in the same directory as ACT3-2.py
(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('\sout', myStr) printRegex('\wout', myStr) printRegex('\w+out', myStr) printRegex('[\s\w]out', myStr) printRegex('[\s\w][Oo]ut', myStr)
it
.it
. A word should be surrounded by whitespace. There are five instances of the word it
.it
and at least one other letter. There are six such words.ing
. There are two such words.She'd
and I'll
), but write the expression to return any contraction.