13.3.1 Problem
13.3.2 Solution
The key to this is carefully defining what you mean by a word.
Once you've created your definition, use the special character types to create
your regular expression:
/\S+/ // everything that isn't whitespace /[A-Z'-]+/i // all upper and lowercase letters, apostrophes, and hyphens
13.3.3 Discussion
The simple question "what is a word?" is surprisingly
complicated. While the Perl compatible regular expressions have a built-in word
character type, specified by \w, it's important
to understand exactly how PHP defines a word. Otherwise, your results may not be
what you expect.
Normally, because it comes directly from Perl's definition of a
word, \w encompasses all letters, digits, and underscores; this means
a_z is a word, but the email address php@example.com is not.