Regular Expressions


To look for a pattern in the string and replace it with something else, use the following syntax:

To do case-insensitive pattern matching, append an i to the substitution.


If you want the replacement to operate on all possible matches instead of just the first match, append a g to the substitution.

To remove all substrings matching the pattern write:
$string =~ s/PATTERN//g;

Note that $string is changed after these operations!


# replace the first occurence of the word ID with "Identification";
$swiss_prot_line =~ s/ID/Identification/;

# replace all occurences of BIU with Bar Ilan University
$addresses =~ s/BIU/Bar Ilan University/g;

# remove all spaces, tabs etc. from a sequence entry
$seq =~ s/\s+//g;

Table of Contents.
Previous | Next.