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.
In reply to Regex word boundary and escaped characters by ryantate
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |