in reply to Re^3: Regex Inline Match operator ?m
in thread Regex Inline Match operator ?m

Thanks for all the responses.....I'm close but still stuck on how I would change it to match when the last line didn't have a newline at the end.

Replies are listed 'Best First'.
Re^5: Regex Inline Match operator ?m
by almut (Canon) on May 06, 2010 at 02:11 UTC

    Have you tried the regex I suggested?  Works for me:

    my $tests = [ 'Nov 29 16:01:27 Nov 29 16:01:28 Nov 29 16:01:28 Nov 29 16:01:28 Nov 29 16:01:22', 'Nov 29 16:01:27 Nov 29 16:01:28 Nov 29 16:01:28 Nov 29 16:01:28 Nov 30 16:01:22' ]; foreach my $test (@$tests) { if($test =~ qr/^((^|\n)Nov 29 [^\n]*)+$/s) { print "$test\n REGEX MATCHED\n"; } else { print "$test\n FAILED!\n"; } } __END__ Nov 29 16:01:27 Nov 29 16:01:28 Nov 29 16:01:28 Nov 29 16:01:28 Nov 29 16:01:22 REGEX MATCHED Nov 29 16:01:27 Nov 29 16:01:28 Nov 29 16:01:28 Nov 29 16:01:28 Nov 30 16:01:22 FAILED!

    Or modify ikegami's regex like this:

    qr/^(?:Nov 29 [^\n]*(\n|$))*\z/s ^^^^^^ newline or end-of-line
      Thanks a ton, that works perfectly!
Re^5: Regex Inline Match operator ?m
by ikegami (Patriarch) on May 06, 2010 at 03:14 UTC