in reply to Regex Help

Dru,
Are you sure thats a \n newline?
#!/usr/bin/perl use strict; use warnings; my $output = "Output: Got .\"ATDT123456\nBUSY"; print "matched\n" if $output =~ /ATDT\d+\nBUSY/m; # or print "matched\n" if $output =~ /ATDT\d+.BUSY/s;
Cheers - L~R

Update: The first question is to imply that there is more than one way to get an apparent newline. Win32 for instance uses \r\n as line endings.

Replies are listed 'Best First'.
Re^2: Regex Help
by Dru (Hermit) on Jun 07, 2004 at 14:56 UTC
    Thanks for the response L~R, Yes, this is Win32. I tried:
    print if /ATDT\d+.BUSY/s; print if /ATDT\d+.*BUSY/s; print if /ATDT\d+\r\nBUSY/m;
    and I'm still not matching. Something that I didn't mention in the first post, that I didn't feel was relevant, but maybe it is. In this file, each line ends with a ^M character (I forget what these are called, form feeds?), but when I print out the entire file in a while loop, they do not appear, so I figured they did not effect the regex or do they? If they did, then this one should still work print if /ATDT\d+.*BUSY/s; right?
      Dru,
      I am surprised that /ATDT\d+.*BUSY/s does not work. I would suggest an octal dump and since you are on Win32, you might need Perl Power Tools. It will show you what you can't see ;-)

      Cheers - L~R

        Or use perl itself for a rudimentary dump of the stream:
        echo "ATDT123456 \r\nBUSY" | perl -e 'local $/=undef;@chars=split //, +<STDIN>; for(@chars) {print $_ . " " . ord($_) . "\n"; }'