|Next||Regular Expression Mastery||68|
/s: Make . match newline (normally it doesn't)
/m: Make ^ match at beginning of line (after a newline) rather than beginning of string, and similarly $
Example: Suppose $message contains an entire mail message.
($subject) = ($message =~ /^(Subject:\s+(.|\n\s)*)$/m);
Extracts Subject field.
If you use /m, use \A and \Z to get the old meanings of ^ and $: Match at beginning or end of string only
Recall that $ normally matches before a newline at the end of the string. \Z does that too.
If you really want to match only at the end of the string, use \z
Perl 6 will fix this mess; /s and /m are going away:
^ beginning of string $ end of string ^^ beginning of line $$ end of line . match any single character \n match a newline \N match any single character except a newline
|Next||Copyright © 2002 M. J. Dominus|