#!/usr/local/bin/perl
#
use strict;
use warnings;
our @tryThese = (
"a 10\nb a2 s2\nc 30",
"a 10\nb\nc 30",
"a 10\nb \nc 30",
"a 10\nb a2 s2 \nc 30");
our $c;
our $rxAfterB = qr{(?m)^b[\x20\x09]*([^\n]*)};
Loop over @tryThese printing out what we are testing, doing the match then showing the result.
foreach my $a (@tryThese)
{
print "\n\$a contains ...\n";
{
local $" = "<--\n";
print "@{[split /\n/, $a]}\n";
}
($c) = $a =~ /$rxAfterB/;
print "c is -->$c<--\n\n";
}
When run this produces
$a contains ...
a 10<--
b a2 s2<--
c 30
c is -->a2 s2<--
$a contains ...
a 10<--
b<--
c 30
c is --><--
$a contains ...
a 10<--
b <--
c 30
c is --><--
$a contains ...
a 10<--
b a2 s2 <--
c 30
c is -->a2 s2 <--
I hope this is of use. Cheers, JohnGG
Update: The slashes around the compiled regular expression in the line ($c) = $a =~ /$rxAfterB/; are superfluous. The line should read
($c) = $a =~ $rxAfterB;
JohnGG |