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

I'm looking for some regex help with how to create an inline multi-line match. I can't change the outside modifiers qr and s, so what would be the best regex inside the // to help with the following match criteria. I want the match to pass if every line has Nov 29 but if it has any lines that start with other dates it should not match.

(I realize the regex below is wrong but wasn't sure what the best approach would be)
if($test =~ qr/(?m:^Nov 29).$/s) {

(Should fail)
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


(Should pass)
Nov 29 16:01:27
Nov 29 16:01:28
Nov 29 16:01:28
Nov 29 16:01:28

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

     /^((^|\n)Nov 29[^\n]*)+$/s should work.

      I added a space after the day in mine. It's not a likely to be a problem for Nov 29, but if he reuses the regex for Dec 1 (for example), the lack of space will let other dates (such as Dec 18) through.
Re: Regex Inline Match operator ?m
by ikegami (Patriarch) on May 06, 2010 at 01:01 UTC
    my $re = qr/^(?:Nov 29 [^\n]*\n)*\z/s; print(/$re/ ? "pass\n" : "fail\n") for <<'__EOI__', <<'__EOI__'; 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 __EOI__ Nov 29 16:01:27 Nov 29 16:01:28 Nov 29 16:01:28 Nov 29 16:01:28 __EOI__
    fail pass
      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!

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