in reply to Regexp explanation
(\w|') matches either a word char or a single quote. Because the left paren here is the 2nd left paren in the regex, this captures into $2.while ($string =~ /((\w|')+)/g) {
((\w|')+) matches one or more occurences of (\w|'). Because of the first left paren, this captures into $1. $2 will be the same as the last char of $1.
//g in a scalar context returns the next match, so the while will continue until all matches are found.
If you just want to add hypenated words, try this:
while ($string =~ /(([\w'-])+)/g) {...do something...}
Update: To get everything surrounded by whitespace, use
but this captures more than \w was doing. Or use split. Or see perlre.while ($string =~ /((\S)+)/g) {...do something...}
-QM
--
Quantum Mechanics: The dreams stuff is made of
|
|---|