Reputation: 559
If I have the following data:
<br/>
help can be found...
So I've got this with respects to the actual data:
<br/>\n\s\s\s\shelp can be found
I can't figure out why, but Perl is not finding these matches. I'm using the following code:
my $filename = $ARGV[0];
open(INFILE, "<", $filename);
while (<INFILE>){
if (/(\<br\/\>.*\s{4}[A-Z])/msi){
print $1."\n";
}
}
to test if Perl returns the parts in my text document that match this regexp, but it not finding them. I can't see what is wrong with my regexp. Any help would be much appreciated. I'm trying to get Perl to match across the newline character but not working.
Upvotes: 1
Views: 322
Reputation: 5348
<INFILE>
in a while loop loads each line into $_
individually. So to match across lines you need to set $/
to undef. You also then need to move the while loop to the regex and use the global flag to set multiple matches.
my $filename = $ARGV[0];
$/ =undef;
open(INFILE, "<", $filename);
my $file = <INFILE>;
while ($file =~ /(\<br\/\>.*\s{4}[A-Z])/msig){
print $1, "\n";
}
Upvotes: 1