in reply to //s modifier

AFAIK you will need either the /m or /s operator - otherwise your regex will only ever look at a single line.

If you use /m, then you will still need to handle newlines (since . won't match a newline). If you use /s, then . will match newlines, so will lead to a shorter regex.

(Not tested)

/<title>.*resultados.*<\/title>/is is equivalent to: /<title>.*\n?.*resultados.*\n.*<\/title>/im
Tom Melly, tom@tomandlu.co.uk

Replies are listed 'Best First'.
Re^2: //s modifier
by tirwhan (Abbot) on Mar 21, 2006 at 11:54 UTC
    AFAIK you will need either the /m or /s operator - otherwise your regex will only ever look at a single line.

    No, that's not true, see below one-liner.

    perl -e '$t="hello\nmoto";print "yep\n" if $t=~m/hello\smoto/;'

    All the s modifier does is to change dot (.) to match newline characters and all the m modifier does is to make ^ and $ match at the beginning/end of each line instead of the whole string. See perldoc perlre.


    All dogma is stupid.
Re^2: //s modifier
by timos (Beadle) on Mar 21, 2006 at 11:45 UTC
    I don't think that the two regexes are equivalent. The first one matches <title>resultados\n\n\n</title> the second doesn't.

      Sorry - should have said "similiar to" ;)

      Anyway, my real bad was saying he'd need one of the modifiers to ever hope on matching a multi-line regex... what was I thinking? (well, I know what I was thinking - got in a muddle over iterating, line-by-line, through a file, etc.).

      Tom Melly, tom@tomandlu.co.uk