Due Thursday, July 19, at the start of class.
Practice writing regular expressions.
You are not writing a script this time! Instead, I provide the script (similar to the one we used in class):
#!/usr/bin/perl use strict; use warnings; open(INPUT, '<', $ARGV[0]) or die "Could not open file: $!\n"; while (<INPUT>) { print if /cat/; # PUT YOUR REGEXP IN PLACE OF /cat/ } close INPUT;
Your assignment is to write regular expressions for the following patterns. Use the script to test your expressions. To help with testing, here are the two data files that I used in class:
For some of the patterns, you may wish to create your own input file(s). That is fine.
Most of the patterns below are narrowly defined, but some permit more freedom of interpretation. If you think that the description of a pattern is not clear, your answer must include a description of how you interpreted it; include example matches and non-matches to support your interpretation. If your pattern does not match my interpretation, or a fairly obvious other one, it will not count.
You must get at least 11 of the 15 patterns below correct in order to get full credit for the assignment. Thus, if you do only 11 of the patterns and get one wrong, you will not get two points. Give yourself time, and be sure to check both matches and possible non-matches!
Think carefully about whether letter case matters in each pattern.
Some patterns are prefixed with “[words]” to indicate that the pattern should work on the words data file, and some are prefixed with “[Henry]” to indicate that the pattern should work on the King Henry V data file. Other patterns are for other data.
Be sure to test each regular expression using the script above and some real input. I can tell when you have not tested!
One common problem with regular expressions is to write one that does indeed match all strings you want it to match, but then also match many strings you do not want to. Watch out for the latter. Remember: A regular expression partitions all strings into matching and non-matching. Make sure you do not over-match.
Do the work yourself, consulting reasonable reference materials as needed. Any resource that provides a complete solution or offers significant material assistance toward a solution not OK to use. Asking the instructor for help is OK, asking other students for help is not. All standard UW policies concerning student conduct (esp. UWS 14) and information technology apply to this course and assignment.
A printout of your regular expressions, clearly labeled, on a single sheet of paper. Provide any necessary qualifications for your expressions, including example matches and non-matches. Be sure to put your own name in the initial comment block of the code. Identifying your work is important, or you may not receive appropriate credit.