Re: Regular expression over multiple lines issues
- From: noreply@xxxxxxxxx (Gunnar Hjalmarsson)
- Date: Fri, 28 Sep 2007 03:58:24 +0200
glenn.pringle@xxxxxxxxx wrote:
My problem is that the regular expression is only displaying the first
item (mrn) but it won't display the others (enc, date,
report_subtitle)
My code is on the following line
#!/usr/bin/perl
#open(FILE, "3688001.ps");
open(FILE, "1234567.txt");
while ($buf = <FILE>) {
Since your regex spans over multiple lines, you can't just read one line at a time.
local $/ = "end\n";
while (my $buf = <FILE>) {
Read about the $/ variable in "perldoc perlvar".
#print "$buf\n";
if ($buf =~ m/\%mrn\%(\d+).+
\%enc\%(\d+).+
\%date\%
(\d{1,2})\/
(\d{1,2})\/
(\d{1,2})\^.+
Year may have four digits.
(\d{2,4})\^.+
^\%report_subtitle\%(.+)\(
You probably want that to be non-greedy.
^\%report_subtitle\%(.+?)\(
Read about greediness in "perldoc perlre".
/xms) {
<snip>
I would appreciate if anybody can tell me what I'm doing wrong or
missing.
See comments above.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.
- References:
- Regular expression over multiple lines issues
- From: Glenn.Pringle@xxxxxxxxx
- Regular expression over multiple lines issues
- Prev by Date: Re: Open File - Read Only
- Next by Date: Re: Regular expression over multiple lines issues
- Previous by thread: Regular expression over multiple lines issues
- Next by thread: Re: Regular expression over multiple lines issues
- Index(es):
Relevant Pages
|