ryantate has asked for the wisdom of the Perl Monks concerning the following question:
The regex word boundary meta character, \b, does not seem to match start of string if the first word character of the string is escaped. Is this expected behavior?
Here is an example of the behavior in question:
apocalypse.OCF [178] perl5.8.5 -e 'my $s = "\@testing"; $s =~ s/\b\@testing\b//i; print "$s\n";' @testing apocalypse.OCF [179] perl5.8.5 -e 'my $s = "+testing"; $s =~ s/\b\+testing\b//i; print "$s\n";' +testing apocalypse.OCF [180] perl5.8.5 -e 'my $s = "testing"; $s =~ s/\btesting\b//i; print "$s\n";' apocalypse.OCF [181]
For now I'm using (\b|^)\@testing(\b|$) as a workaround, but this behavior seems at odds with perlre, which states:
A word boundary ( \b ) is defined as a spot between two characters that has a \w on one side of it and and a \W on the other side of it (in either order), counting the imaginary characters off the beginning and end of the string as matching a \W .
Is this a bug?
Update: No, of course, it's not a bug. @ and + being non word chars, there is no \w char to match. Duh. ;--> Thanks for the many quick responses.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex word boundary and escaped characters (as designed)
by tye (Sage) on Jan 26, 2005 at 23:12 UTC | |
|
Re: Regex word boundary and escaped characters
by Paladin (Vicar) on Jan 26, 2005 at 23:13 UTC | |
|
Re: Regex word boundary and escaped characters
by dave_the_m (Monsignor) on Jan 26, 2005 at 23:14 UTC | |
|
Re: Regex word boundary and escaped characters
by Roy Johnson (Monsignor) on Jan 27, 2005 at 03:18 UTC | |
|
Re: Regex word boundary and escaped characters
by Eimi Metamorphoumai (Deacon) on Jan 27, 2005 at 14:19 UTC |