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

Greetings,

I'm having a regex problem that I hope you can help me with. Consider this test:

like( $content, qr(<td>$args->{class}</td> .* <td>$args->{timestamp}</td> )msix , '/report/classes dr_test_class ' );

And the results:

# Failed test '/report/classes dr_test_class ' # at ./nhw.pl line 153. # '<tr> # <td>dr_test_class</td> # <td>2014-07-23 18:01:01-04</td> # </tr> # # ' # doesn't match '(?^msix:<td>dr_test_class</td> # .* # <td>2014-07-23 18:01:01-04</td> # )'

Why does the match fail?

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re: Help with regex and 'like' in test::more
by Your Mother (Archbishop) on Jul 23, 2014 at 18:49 UTC

    It seems to be deciding there are special chars in the timestamp. Try this version (\Q\E is really all that changed)–

    use Test::More; my $content = <<""; <tr> <td>dr_test_class</td> <td>2014-07-23 18:01:01-04</td> </tr> my $args = { class => "dr_test_class", timestamp => "2014-07-23 18:01:01-04" }; like $content, qr{<td>$args->{class}</td> .* <td>\Q$args->{timestamp}\E</td> }xis, '/report/classes dr_test_class'; done_testing();

      I can repeat your results. I wonder what the root cause is.

      Neil Watson
      watson-wilson.ca

        I was puzzled too, then considered the x modifier. The timestamp has a space in it. :P

Re: Help with regex and 'like' in test::more
by Anonymous Monk on Jul 23, 2014 at 19:07 UTC
    use re 'debug'; ?