Due Monday, July 25, at the start of class.
Practice writing regular expressions.
You are not writing a script this time! Instead, I provide the script (same 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/; } 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 narrowed defined, but some permit more freedom of interpretation. If you think 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 7 of the 10 patterns below correct in order to get full credit for the assignment. 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.
Do the work yourself, consulting reasonable reference materials as needed; any reference material that gives you a complete or nearly complete solution to this problem or a similar one is not OK to use. Asking the instructors for help is OK, asking other students for help is not.
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.