If you're looking for a space, that would be " "
(one space).
If you're looking for one or more, it's " *"
(two spaces and an asterisk) or " +"
(one space and a plus).
If you're looking for common spacing, use "[ X]"
or "[ X][ X]*"
or "[ X]+"
where X
is the physical tab character (and is preceded by spaces in all those examples).
These will work in every RE engine I've ever seen (some of which don't even have the one-or-more "+"
character, ugh).
If you know you'll be using one of the more modern RE engines, "\s"
and its variations are the way to go. In addition, I believe word boundaries match start and end of lines as well, important when you're looking for words that may appear without preceding or following spaces.
For PHP specifically, this page may help.
From your edit, it appears you want to remove all non valid characters The start of this is (note the space inside the RE):
$newtag = preg_replace ("/[^a-zA-Z0-9 ]/", "", $tag);
If you also want trickery to ensure there's only one space between each word and none at the start or end, that's a little more complicated (and probably another question) but the basic idea would be:
$newtag = preg_replace ("/ +/", " ", $tag);
$newtag = preg_replace ("/^ +/", "", $tag);
$newtag = preg_replace ("/ +$/", "", $tag);