Break it down to its components. [] builds a character set. Inside you've got \w and \s, which would normally match a word character or a space character. You've got an extra backslash in your question which isn't present in the cookbook regular expression. So get rid of that -- it's not really part of your intended question.
Now, we've just about got it figured out, except there's that pesky ^ character, which turns out to negate the character class. So now it doesn't match words and spaces. Now it will match anything that is NOT a word or space character.
The final step is the +, which tells perl to match one or more times. So it must match at least one or more characters that are NOT word or space characters.
Word characters are usually A-Za-z_0-9 (A to Z caps and lowers, plus underscore and digits zero through nine). Space characters are what we generally think of as 'whitespace'.
So to summarize, match any non-word or non-space character, and match as many as possible with a minimum of one.
Update: Are you sure that's exactly the example from the Perl cookbook? I don't have my old copy handy, but that sub dequote; right at the beginning looks odd to me, though it's not actually a problem. It just seems odd given the context.
Update 2: You could also use YAPE::Regex::Explain to check for an explanation yourself. ...or you could use it to verify the accuracy of my description. ;).
use YAPE::Regex::Explain;
print YAPE::Regex::Explain->new('[^\w\s]+')->explain();
And the relevant output:
[^\w\s]+ any character except: word characters (a-
z, A-Z, 0-9, _), whitespace (\n, \r, \t,
\f, and " ") (1 or more times (matching
the most amount possible))
Ta-da!
|