in reply to Re: regexp need a match characters and spaces
in thread regexp need a match characters and spaces

You could try the following as it seems to cope with spaces between the b and it's newline and with b with an immediate newline by making the spaces optional and also making a character class that excludes newline, unlike \s.

Set up some text to try and set up the regular expression.

#!/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