yusy has asked for the wisdom of the Perl Monks concerning the following question:

Could someone teach me how it works when 's' and 'm' both appear in this regexp?

Thanks

$data=~m/(.*?$string(?:[^\n]*\n){1,10})/ismo

Replies are listed 'Best First'.
Re: regexp question
by JavaFan (Canon) on Jul 20, 2011 at 20:37 UTC
    /s and /m don't interfere with each other. /s influences the meaning of a dot, /m influences the meaning of ^ and $.
Re: regexp question
by kennethk (Abbot) on Jul 20, 2011 at 20:39 UTC
    Please wrap code in <code> tags -- see Markup in the Monastery. Note that your character class got linkified because you did not do this.

    This behavior is documented in the Modifiers section of perlre:

    m

    Treat string as multiple lines. That is, change "^" and "$" from matching the start or end of the string to matching the start or end of any line anywhere within the string.

    s

    Treat string as single line. That is, change "." to match any character whatsoever, even a newline, which normally it would not match.

    Used together, as /ms, they let the "." match any character whatsoever, while still allowing "^" and "$" to match, respectively, just after and just before newlines within the string.
Re: regexp question
by cdarke (Prior) on Jul 21, 2011 at 07:14 UTC
    You might be confusing the 'm' on the left of the regexp with the 'm' on the right.

    The 'm' on the left is the match operator, if it was an 's' it would be the substitution operator. See "Regexp Quote-Like Operators" in perlop.

    However on the right the 'm' and 's' are not operators but regexp modifiers, as explained by others above.
Re: regexp question
by onelesd (Pilgrim) on Jul 20, 2011 at 22:05 UTC
    # perldoc perlre