Re: multi-line regular expression help



Cesar Baquerizo wrote:
Hello,

I am having a problem trying to match both of the following strings:

03/23 THU 07:09A (b12:00P b12:30P) 04:30P 8:00 0:00 0:00

as well as (embedded newline):

03/27 MON 07:59A [ 11:59A 12:44P] (b12:45P
b01:15P) 04:30P 8:00 0:00 0:00

The first string always matches, but the second never matches. I've
tried different incarnations of the following regex with no success:

(/^\s*\d\d\/\d\d\s+[A-Z][A-Z][A-Z]\s+.*\d\:\d\d\s+\d\:\d\d\s*$/ms)
^^

Odd, they both match just fine for me:

#!/usr/bin/perl
use strict;
use warnings;

#any newline in string below is the result of newsreader-wrapping
$_ = '03/23 THU 07:09A (b12:00P b12:30P) 04:30P 8:00 0:00
0:00';

if (/^\s*\d\d\/\d\d\s+[A-Z][A-Z][A-Z]\s+.*\d\:\d\d\s+\d\:\d\d\s*$/ms) {

print "First matched\n";
}

#newline in below string after '12:45P'
$_ = '03/27 MON 07:59A [ 11:59A 12:44P] (b12:45P
b01:15P) 04:30P 8:00 0:00 0:00';

if (/^\s*\d\d\/\d\d\s+[A-Z][A-Z][A-Z]\s+.*\d\:\d\d\s+\d\:\d\d\s*$/ms) {

print "Second matched\n";
}
__END__
First matched
Second matched


Perhaps you could post a short-but-complete script (as recommended by
the Posting Guidelines - have you read them yet?) which demonstrates
your error?

Paul Lalli

.



Relevant Pages

  • Re: Read strings from one file and search for them in a directory containing htm files
    ... I have some doubts about the above gawk script. ... There are two variables - string and strings. ... unexpected newline ...
    (comp.unix.shell)
  • Re: Unexpected regex Behavior
    ... wish to do special processing if any chunk ends with the carriage-return ... the "^" character is guaranteed to match only the beginning ... the "$" character only the end (or before the newline at ... the string contains only one line. ...
    (comp.lang.perl.misc)
  • Re: puts behaviour
    ... $stderr). ... is just a progress indicator, ... There should be a newline after your string, though (if not, then ...
    (comp.lang.ruby)
  • Re: Scanf being missed?
    ... to read a string containing white spaces. ... 's' with the tab or newline, ... and again fail to match. ...
    (comp.lang.c)
  • Re: Generating Excel XML with embedded char(10)s
    ... but didn't get any response so I thought I'd try here. ... place of the line feeds (NEWLINE worked for me). ... simply replace the string NEWLINE with the string CHAR. ... using Unicode character reference for linefeed ...
    (microsoft.public.excel.misc)