Summary of Perl Regular Expressions


          . Matches any character except new line
   [a-z0-9] Matches any single character of set
  [^a-z0-9] Matches any single character not in set
         \d Matches a digit, same as [0-9]
         \D Matches a non-digit, same as [^0-9]
         \w Matches an alphanumeric (word) character [a-zA-Z0-9_]
         \W Matches a non-word character [^a-zA-Z0-9_]
         \s Matches a whitespace char (space, tab, newline etc)

         \n Matches a newline
         \r Matches a return
         \t Matches a tab
         \f Matches a formfeed
         \b Matches a backspace (inside [] only)
         \0 Matches a null character
       \000 Also matches a null character, because...
       \nnn Matches an ASCII character with an octal value nnn
       \xnn Matches an ASCII character with a hex value nn
        \cX Matches an ASCII control character
  \metachar Matches the character itself (\|,\.,\* etc)

      (abc) Remembers the match for later backreferences
         \1 Matches whatever first set of parens matched
         \2 Matches whatever second set of parens matched 
         \3 ..etc etc

         x? Matches 0 or 1 x's, where x is any of the above
         x* Matches 0 or more x's
         x+ Matches 1 or more x's
     x{m,n} Matches at least m x's but no more than n

        abc Matches all of a, b and c in order
fee|fie|foe Matches one of fee, fie or foe

         \b Matches a word boundary (outside [] only)
         \B Matches a non-word boundary
          ^ Anchors match to the beginning of a line or string 
          $ Anchors match to the end of a line or string 

A good general discussion of PERL can be found in

Wall, L. & Schwartz, R. (1992) Programming Perl. O'Reilly & Associates, Sebastapol, CA, US.


Web Manager / perlrexp.htm / web@psy.uwa.edu.au