As long as you're doing that ...
By using zero-width assertions on both sides, we don't need to actually match anything. We're matching, literally, zero characters - we're matching simply a location with no length associated. Note, however, that I would make it just a bit different for a bit more flexibility:$ perl -e '$s="JustAnotherPerlHacker\n"; $s=~s/(?<=.)(?=[A-Z])/ /g; pr +int $s' Just Another Perl Hacker
$s=~s/(?<=\S)(?=[[:upper:]])/ /g
Match the location between a non-space and a capital letter. Using a character class gives us flexibility for other languages.
This may also be useful for splitting:
Since split is splitting on nothing, there is nothing actually removed.$ perl -e '$s="JustAnotherPerlHacker\n"; @a = split /(?<=\S)(?=[[:uppe +r:]])/, $s; print "@a"' Just Another Perl Hacker
In reply to Re^4: add spaces after caps & reduce whitespace to single space
by Tanktalus
in thread addd spaces after caps & reduce whitespace to single space
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |