Exercise 2: Regular Expression
Tutorial
The site regexone.com contains a
tutorial and practice problems covering regular expressions. For this
exercise you will go through the tutorial and problems. This will give you
experience writing REs and discuss details about REs that are not covered
in class. Start by reading through the tutorial and then do the practice
problems. You will then submit an evidence document of just the
practice problems.
More specifically, the evidence document consists of screenshots capturing
your answer and the website's response for each of the practice
problems. Be careful! The tutorial exercises and the practice
problems are similar. The
first problem to be captured is shown to the to the
right. Note the keyword "Problem" at the top of the page - the
tutorial exercises are marked with "Lesson". In addition, note the
following:
- Some of the problems can be solved by writing expressions
like
[^x]
- that is, ignoring the problem statement and
matching anything not containing (say) an x. To receive full credit,
you must match all of the key portions of the input. There are specific
notes below about what "key portions" need to be matched - be sure to
check these as you solve the practice problems. For see this
concreteness, screenshot for the first
problem (with the solution grayed out).
- There are many ways to solve each problem, so there is no reason
your solution has to match another's.
- Make sure your document shows that you did solve the problems,
including capturing which problem is being solved. The
quality of your evidence does matter. You must use a screen shot (as
opposed to copy/paste), and you must crop your screen shots down to the
bit that gray box showing both the problem number, the cases to be
matched, your solution pattern, and that there are green check marks for
the required cases.
- Do not include the tutorial exercises in the evidence
document, just the problem section.
- You can work with other students on this assignment, but be careful
that you are actually learning the material. You will see regular
expressions on future quizzes and exams, including when applying for
jobs.
- Submit your answer on Canvas as a PDF. Be sure to include your name
at the top of the document!
Specific notes on problems
- matching numbers: ensure you match the full number. As a side note, these
are Ada-style floating-point constants in that they allow commas.
- matching phone numbers: match the full number, but do not match
things like (abc) 123-4567
- match (capture) just the username (as stated in the problem); do not
match the text at or after either the + or the @
- match the open < followed by the tag name ("a", "href", etc.) but
not any of the text following the tag name or any of the text following
the opening tag.
- match the full filename, including the extension
- follow the directions in the problem statement
- match the full log entry, including the "E/" and the line number at
the start of the line (allowing for line numbers with 1 or more digits);
use capture groups for the appropriate bits within the line
- match the full URL, including text after the last /
DoS Attacks
For entertainment, read about
how regular expressions can be used
for
denial of service
attacks
Grading Rubric
Approximate penalties for specific, common errors. Novel errors often
result in adding to this list.
- Matching all required cases, but failing to address the above specific
notes on a problem: -1
- Failing to match a required case: -1 to -2
- Unreadably small text (due to capturing too much of the screen): -2
- Capturing the exercises rather than the problems: -7