Perls Before Swine: Reference: Regular expressions

  1. File tests
  2. Reference
  3. SilverService

Remember that you can add an “i” to the end of a regular expression to make it ignore upper and lower case.

Character Meaning
. a single character
[characters] a single character from a list or range of characters
[^characters] a single character not from a list or range of characters
? zero or one of the preceding piece of text
+ one or more of the preceding piece of text
* zero or more of the preceding piece of text
(text) group pieces of text for remembering later in $0 to $9 or for applying a ?, +, or *
| choose between two or more options in a group of pieces
^ anchor the expression to the beginning of the line or text being searched
$ anchor the expression to the end of the line or text being searched
\character backquote the next character so that it means what it is rather than its meaning as a regular expression.

For example, you might use /Dean ([A-Z]\. )?Martin/ to match Dean Martin, Dean M. Martin, Dean Q. Martin, or Dean Z. Martin.

Use =~ to see if the item on the left matches the regular expression, and !~ to see if the item on the left does not match the regular expression.

  1. File tests
  2. Reference
  3. SilverService