Regular Expression Lab                
In this lab, you will gain practice using regular expressions. A skeleton source file is in ~cs253/Lab/Regex/regex.cc. Copy it to a convenient directory and modify it during this lab.                 
Template                
The file ~cs253/Lab/Regex/regex.cc contains:
Exercises                
regex.cc
contains a number of calls to the function test()
,
which takes a regular expression, matches it against the string
A quick brown fox jumps over the lazy dog
, and displays
the location and text of any match.
                
You will replace each placeholder regular expression
"regex goes here"
with a regular expression that performs the task
described in the previous lines. The first exercise is already done.
                
- Write a general-purpose regular expression to accomplish the
given task. For example, if I asked you to match a three-letter word,
you shouldn’t look at the sample sentence, decide that “fox” is a
three letter word, and then write the regular expression
"fox"
. I want the computer doing the pattern matching, not you. - For example, in exercise #1,
test()
should produce this output:
1: pattern="jump" target="A quick brown fox jumps over the lazy dog" at 18: "jump"
- The 18 means that “jump” was found at offset 18 of the target string.
- Refer to the Regular Expressions lecture as needed.
- Remember, backslashes (
\
) are special in C++ strings. To get an actual backslash into a C++ string, you must double it (\\
). - If your regular expression contains many doubled backslashes, consider
using a
R"(raw string)"
so you don’t have to double the backslashes. - When you’re done, copy
regex.cc
torecit15.txt
so you can turn it in. Inspect yourrecit15.txt
to ensure that it contains what you want.
How to submit your work:                
Use web checkin, or Linux checkin:                 
~cs253/bin/checkin RECIT15 recit15.txt
How to receive negative points:                
Turn in someone else’s work.