CS246 Homework 6: Regular Expressions
Due: Monday, April 2 2:30pm
What to hand in:
- Paper printout of the grep/egrep commands for part A.
- Electronic text file consisting of the same commands, copied to /home/dxu/submissions/cs246
- Paper printout of the regular expressions and/or explanations for part B.
The power of regexes [50pts]
- Give the correct grep/egrep command with regular expression for the following patterns. For testing purposes, just make up some test file with appropriate data, you can also copy greptest from /home/dxu/handouts/cs246.
- lines with characters that are not letters or spaces
- lines with no vowels
- lines with exactly 9 characters
- lines with at least 9 characters
- lines with odd number of characters
- lines that end with two digits
- lines with 2 0s
- lines with 2 consecutive 0s
- lines with a 5 letter word
- lines with a word of at least 5 letters
- lines containing patterns that start and end with the same letter
- lines containing patterns that start and end with the same letter and with odd number of letters in between
- lines containing a repeated word of 2 letters separated by a space, i.e. "55 55"
- lines containing 9 consecutively repeated digits, i.e. "000000000", or "222222222"
- lines containing 3 repeated digits, not necessarily consecutive, i.e "3 3 3", "55 5", "666" or "a6b6c6d"
- lines with exactly 2 words
- In addition, write the regular expressions that generate the following sets, if possible. If not, give reasons why. Note that bitstrings are strings that consists of 0's and 1's only. Also, your expressions must be complete, meaning that it should generate all possible bitstrings that satisfy the given criteria, not just a subset.
- Bitstrings that begin with 0 and end with 1.
- Bitstrings that has 011010 as a substring.
- Bitstrings with equal number of 0’s and 1’s.
- Bitstrings that have no consecutive 1’s.
- Bitstrings that have an odd number of 0’s.