How about this comment :-)
s//#Just#Another#Perl#Hacker#/; s/\b\W/$1 /g; print;
You can even help with speech recogition for stutter challenged hackers
s//J-J-J-J>Just Another Perl Hacker/; s/\b\w\b//g; print;
Personally I don't use \b much. One of the big problems I find with regexes is accidentally matching things you did not meant to, so I try to be as specific as possible. Rather than specify a boundary I specify exactly what I want to follow. If you don't want to eat up your string you can use the lookahead assertions so the zero width nature of \b has no advantage on that front. These expressions are similar:
# using boundaries s//#foo foo foobar foo#/; s/\bfoo\b//g; print; # using negative lookahead and lookbehind assertions s//#foo foo foobar foo#/; s/(?<!\w)foo(?!\w)//g; print; # using positive lookahead and lookbehind assertions with char classes s//#foo foo foobar foo#/; s/(?<=[^\w])foo(?=[^\w])//g; print;
The difference is that with the lookaround assertions I have much greater control as I can use a character class in them as shown.
TIMTOWTDI
cheers
tachyon
In reply to Re: Regular Expressions
by tachyon
in thread Regular Expressions \b and \B
by vbrtrmn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |