ULI101 - Regular Expressions

Prof. Anthony Austin
Weight if completed 2%
Due Date: November 16, 2018

Student Name:_________________________________________
Student Number:_______________________________________

This exercise is one in which you must identify the characters that the supplied regular expressions, with the sample text, identifying line numbers where necessary.

Created by The Gimp

You can do this exercise in vi by inputting the sample text and HITTING THE ENTER KEY AT THE END OF EACH LINE. Save the files as regex.lab in your home directory USE THE LASTLINE SUBSTITUTE COMMAND AND THE UNDO COMMAND so you original is never altered (it might also be wise to make a backup of the original just in case). This will allow you to see what has been altered without permanently altering it. NOTE: \< \> is vi for \w in PHP, grep and sed. Some characters in the exercise will not work in vi. Indicate what they are

In answering Questions use the following examples:

What will the following regular expressions match:


Every instance of the string "match" at the end of the line on all lines that is preceded
by zero or more characters and subsititute with MATCH


From lines 1 to ten substitute the string "/bin" following by one or more instances of a
single character zero or matches and //, substitute with the string "home" all instances on
the line

What will be matched in the following regexes:


The character $ followed by the HOME on the next line

What do the following regular expressions replace:

NOTE: There are three regular expression that will produce an error, explain why
1. :1,$s/^/> /

2. :1,$s/the/THE/

3. :1,$s/a.*e/XXX/

4. :1,$s/[Tt].*[.]/XXX/

5. :1,$s/expressions/expresssions/

6. :1,10s/literal/LITERAL/

7. :1,$s/\/Literal/

8. :1,$s/^.*$/XXX/

9. :1,$s/^..*$/XXX/

10. :1,$s/^.*.$/XXX/

11. :1,$s/s*/sXXX/

12. :1,$s/ss*/sXXX/

13. :1,$s/\*ss*\/sXXX/

14. :1,$s/[A-Z]\.[A-Z]/XXX/

15. :1,$s/a.*{3}/XXX/

16. :1,$s/a..*{0,1}/XXX/

17. :1,$s/a[^ ]/XXX/

18. :1,$s/a[^r].*/XXX/

19. :1,$s/[A-Z][0-9]/XXX/

20. :1,$s/\<[a-zA-Z][0-9]\>/\&/

What do the following regular expressions match:

1.    ^#$

2. $PATH

3. $[$PATH]

4. \$$PATH

5, ^...$

6. "word"

7. "*word*"

8. \*word*\

9. \<word\> ( or \bword\b in Perl)

10 [^w]ord


Complete the questions and submit in hard copy or via email (filename exer4sub) by the due date.