Assumed knowledge

You should already be familiar with the following topics:

Patterns and regular expressions are dealt with in depth in chapter 2 of the Camel book, and further information is available in the online Perl documentation by typing perldoc perlre.

Review exercises

The following exercises are intended to refresh your memory of basic regular expressions:

  1. Write a script to search a file for any of the names "Yasser Arafat", "Boris Yeltsin" or "Monica Lewinsky". Print out any lines which contain these names. (Answer: exercises/answers/namesre.pl)

  2. What pattern could be used to match any of: Elvis Presley, Elvis Aron Presley, Elvis A. Presley, Elvis Aaron Presley. (Answer: exercises/answers/elvisre.pl)

  3. What pattern could be used to match a blank line? (Answer: exercises/answers/blanklinere.pl)

  4. What pattern could be used to match an IP address such as 203.20.104.241, where each part of the address is a number from 0 to 255? (Answer: exercises/answers/ipre.pl)