in reply to /m pattern matching modifier

YAPE::Regex::Explain might help you here:
(?m-isx:^.*$) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?m-isx: group, but do not capture (with ^ and $ matching start and end of line) (case- sensitive) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ^ the beginning of a "line" ---------------------------------------------------------------------- .* any character except \n (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- $ before an optional \n, and the end of a "line" ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
The .* does not match a newline character, and $ is optional. Perhaps you also want the /s modifier (perlre):
use warnings; use strict; "AAC\nGTT\n" =~ /^.*$/ms; print $&; __END__ AAC GTT

Replies are listed 'Best First'.
Re^2: /m pattern matching modifier
by tandx (Novice) on Oct 21, 2011 at 13:50 UTC
    Thanks for the quick response.
    I can understand how /s modifier changes other metacharacter's behavior, but still have difficulty to under the logic of /m.
    My initial testing code: "AAC\nGTT"=~/^.*$/m only find the first match (thanks to the second perlmonk who responsed to my initial question). Then I tested "AAC\nGTT"=~/^.*$/mg, which still gave AAC. Since .* with /m won't match \n sign, the second part of the string GTT should fit to the regular expression ^.*$ according to /m definition.
    Interestingly, "\nGTT\n"=~/^.*$/m gave nothing,
    while "GTT\n"=~/^.*$/mg shows GTT.
    Thanks