Common Regular Expression Mistakes

  1. Forgetting to enclose the regular expression in ' '.
  2. Including spaces in the regular expressions (other than spaces you want).
  3. Not escaping special characters you want treated literally: e.g. '()' instead of '\(\)'.
  4. Forgetting the ^ and $ when you want an entire line to match a regular expression rather than some substring of the line.
  5. Forgetting that something * includes the null string. For example, the regular expression (aaa|bbb)* matches every line!

Prof Christopher W Brown
Last modified: Tue Sep 12 15:57:02 EDT 2000