This pattern replaces consecutive whitespace characters (note, not just spaces, as well as line breaks or tabs) with one regular space (''). \s+ says that "matches a sequence of one or more space characters".
The # characters are delimiters for the pattern. Probably more common is viewing patterns separated by forward slashes. (Actually, you can do REGEX in PHP without separators, but it does matter how the template is processed, which is beyond the scope of this question / answer).
http://php.net/manual/en/regexp.reference.delimiters.php
Relying on spaces to find words in a string is usually not the best approach - instead, we can use the \b border marker.
$sentence = "Hello, there. How are you today? Hope you're OK!"; preg_match_all('/\b[\w-]+\b/', $sentence, $words);
This says: take all the substrings in the larger string, which consist only of alphanumeric characters or hyphens and are enclosed in word boundaries.
$words now an array of words used in a sentence.
source share