CIS 18B Advanced UNIX

Assignment 1

Regular Expression Exercises


I use the work 'sequence' to indicate that the characters are in order, with NO other characters between them.


Write a regular expression, used with grep -G, that will match each of the following, when executed on voyager.

Use single quotes when needed.

If any additional grep options are needed, specify them.


Make the regular expressions as short as possible.


1. The string contains at least one 'A'

2. The string begins with 'A'

3. The string ends with 'A'

4. The string contains the sequence of two characters 'AA'

5. The string contains 'A' and another 'A' somewhere in the same string (two 'A' somewhere in the string)

6. The string contains the sequence of three letters: 'h' any vowel 'g'

7. The string contains a sequence of 37 occurrences of 'A'

8. The string contains a period

9. The string contains a sequence of a period, followed by a space

10. The string begins with a capital letter

11. The string ends with a numeral

12. The string begins with a sequence of two numerals

13. The string begins with a sequence of two numerals, immediately followed by an alphabetic letter

14. The string begins with a sequence of two numerals, immediately followed by a character that is not a numeral

15. The string contains the character '$'

16. The string ends with the character '$'

17. Every period in the string is followed by exactly three numerals, no more, no less

18. The string contains no characters (except possibly an end of the line character)

19. The string contains exactly three numerals, and no other characters

20. The string contains a sequence of three numerals

21. The string contains three numerals anywhere in the string, and may contain other characters

22. The string contains exactly four characters

23. The string contains three or more characters

24. The string contains three characters, but not more than five characters

25. The string contains the sequence 'the end' at the end of the string