Regular Expressions


Alternation allows matching any one of several subexpressions.

The alternative subexpressions are separated by vertical bar(s) |.

Example 1

Recall the example we used for extracting all lines about human proteins from the Swiss-Prot list of muscarinic acetylcholine receptors.

Let us now change it to extract all lines including either human, rat or mouse proteins:

if ($line =~ /HUMAN|RAT|MOUSE/) {  }

#match line against either HUMAN, RAT or MOUSE

Example 2

In the same file, let us now restrict our search only for the ACM1 receptors in either human, rat or mouse.
if ($line =~ /ACM1_(HUMAN|RAT|MOUSE)/) {  }

# we enclosed the alternative subexpressions in parentheses (HUMAN|RAT|MOUSE)
# and added the receptor name prefix ACM1_ before them.

Table of Contents.