Regular expression question in Linux (Only write the regular expression. Do not
ID: 3891004 • Letter: R
Question
Regular expression question in Linux (Only write the regular expression. Do not include the egrep command and do not enclose it in single or double quotes.):
1. Write a regular expression that you could use with egrep that will match lines in names.txt with a zip code that has “22” in it. NOTE: this should not include Mike Keneally whose street address includes “22”. Only write the regular expression. Do not include the egrep command and do not enclose it in single or double quotes.
2. Write a regular expression that you could use with egrep that will find all entries in /usr/share/dict/words that are exactly 12 characters in length (words longer than 12 should not appear). Only write the regular expression. Do not include the egrep command and do not enclose it in single or double quotes.
3. Write a regular expression that you could use with egrep that will find all entries in /usr/share/dict/words that have a q (or Q) without a u immediately after. Only write the regular expression. Do not include the egrep command and do not enclose it in single or double quotes.
Explanation / Answer
1. (22){6}$ (assuming zip codes are of length 6 and are in the end of the line)
2. ^[A-Za-z0-9]{6}$ (Assuming words are alphanumeric)
3. ^[^ ]*(q | Q)+[^u][^ ]*$