in reply to Re^2: Regular Expression, substitution
in thread Regular Expression, substitution
Actually, it's trickier than that. qr/(?<=\w)(?=\W)|(?<=\W)(?=\w)/ requires a character before and after the assertion, whereas \b can match at the start and end of a string. A kind of double-negative is needed in an equivalent look-around:
c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'xx-xx'; ;; my $lbw = qr/(?<=\w)(?=\W)|(?<=\W)(?=\w)/; printf qq{$-[0] } while $s =~ m{ $lbw }xmsg; print qq{\n}; ;; my $wb = qr{ (?<!\w)(?!\W) | (?<!\W)(?!\w) }xms; printf qq{$-[0] } while $s =~ m{ $wb }xmsg; print qq{\n}; ;; printf qq{$-[0] } while $s =~ m{ \b }xmsg; " 2 3 0 2 3 5 0 2 3 5
Update: Now, \B is another story...
Give a man a fish: <%-{-{-{-<
|
|---|