On 20/07/2010 16:22, Chandan Kumar wrote:
Hi ,
Small confusion about word boundaries. word boundaries matches
anything between non-word character and word character ,right.
Not quite. /\b/ matches any (zero-length) point in a string between a
word and a non-word character, or between a word character and the
beginning or end of the string,
Here is small example :
$_ = "?Jack do you know the beauty of perl"
print "Enter your text:";
my $pattern =<STDIN>;
chomp $pattern;
if (/$pattern/){
print "1.$1\n";
}
Now say I have given pattern as :(\b\W\b) .what will be the result?
My understanding is quotes a (nonword character) ? a (nonword character)
followed by word charatcer "j". The result I have expected ?.
but result is empty string.
Please can some about word boundaries?
(You are aware that /\W/ matches a single NON-word character? /\w/
matches a word character.)
You are asking for the first non-word character with a word character on
both sides. That is the space after 'Jack', bounded by 'k' and 'd'.
HTH,
Rob
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/