in reply to PERL regex modifiers for m//

$s = "foo\nfoot\nroot"; $s =~ /^foo/g; # matches only the first foo $s =~ /^foo/gm; # matches both foo $s =~ /f.*t/g; # matches only foot $s =~ /f.*t/gs; # matches foo\nfoot\nroot $s =~ /f.*?t/gs; # matches foo\nfoot $s =~ /^foot.*root$/g; # doesn't match $s =~ /^foot.*root$/gm; # doesn't match $s =~ /^foot.*root$/gs; # doesn't match $s =~ /^foot.*root$/gms; # matches foot\nroot

Replies are listed 'Best First'.
Re^2: example of 'm / / m' related example and compare to 'm / / s'
by ww (Archbishop) on Nov 28, 2011 at 18:09 UTC
    Line 3: " # matches both foo": are you sure?
    C:>perl -e "$s = \"foo\nfoot\nroot\";($y) = $s =~ /^foo/gm;print $y;" foo
      Yes, but not in the same pass.
      >perl -E"say join ',', qq{foo\nfoot\nroot} =~ /^foo/gm;" foo,foo