Basic HTML version of Foils prepared March 30 97

Foil 42 The Matching Operator in Regular Expressions - I ( =~, m)
(Chapter 7 of the Llama Book)

From PERL4 Tutorial for CPS616 Computational Science for Information Age Course CPS616 -- February 1995. by Geoffrey C. Fox


1 We have finally finished study of regular expressions and have illustrated this for substitution operator (s) acting on default variable $_. We can generalize this operation in many ways
2 The result of ( Variable Name =~ /Regular Expression/ ) is true if and only if value of Variable Name matches Regular Expression. For example
3 if ( <STDIN> =~ /^(T|t)(O|o):/ ) { # <STDIN> is $_
  • ..; # Process to: field of mail } # matches if current input
    • line contains to: with any case at start of line
4 There is an implied match operator above which we can make explicit with m
5 $line =~ m/^(T|t)(O|o):/ and we can use m to change delimiter from / to any character and
6 $line =~ m%^(T|t)(O|o):% # is equivalent to previous statement
7 Note m/^to:/i equivalent to above as modifier i instructs pattern match to ignore case

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Sep 6 1997