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

This fails in my test, I must have changed something....
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' ]; # Put the regex you want to test in here. foreach my $test (@$tests) { if($test =~ qr/^(?:Nov 29 [^\n]*\n)*\z/s) { print "$test\n REGEX MATCHED\n"; } else { print "$test\n FAILED!\n"; } } 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 FAILED!

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

    ikegami's regex requires a trailing newline, which you don't have in your test case.

      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.

        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