in reply to Word boundary '\B' - Question
Neither ' ', '&', nor ';' are word characters, so there is no word boundary between them.
On the other hand, 'a', and 'f' are word characters (and '&' and ';' still aren't), so there are your word boundaries.
You probably want either negative or positive lookahead/lookbehind for (non-)whitespace instead. Negative version:
$str = 'abac ~~~ afa~~~ +;f'; $str =~ s|(?<!\s)\&\#x0007E\;\&\#x0007E\;\&\#x0007E\;(?!\s)|~~~|g; print $str;
Positive lookahead/lookbehind won't match at end/beginning of string:
$str = 'abac ~~~ afa~~~ +;f'; $str =~ s|(?<=\S)\&\#x0007E\;\&\#x0007E\;\&\#x0007E\;(?=\S)|~~~|g; print $str;
print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Word boundary '\B' - Question
by prasadbabu (Prior) on Aug 21, 2006 at 15:46 UTC |