Basic HTML version of Foils prepared Sept 20 97

Foil 46 The Matching Operator and
Regular Expressions

From Tutorial on PERL Computational Science for Information Age Course CPS616 -- Sept 20 97. by Geoffrey C. Fox,Nancy McCracken,Tom Scavo


The result of the expression
$string =~ m/$regex/
is true if and only if the value of $string matches $regex.
For example,
if ( <STDIN> =~ m/^[Tt][Oo]:/ ) { ... }
matches if current input line starts with to: (any case)
Note: m/^to:/i is equivalent to above expression since modifier /i instructs pattern matcher to ignore case
Any delimiter may be used in place of the slash
m%^[Tt][Oo]:% # equivalent to previous expression
The m operator may be omitted, but then slash delimiters are required



© 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 Sun Sep 21 1997