You can use
^[^#+&'"\\\s]+(?:\s[^#+&'"\\\s]+)*$
PHP:
$re = '~^[^\s#+&\'"\\\\]+(?:\s[^\s#+&\'"\\\\]+)*$~';
See the regex demo. This regex does not allow consequent whitespaces and any leading/trailing whitespaces, is linear and fast.
Details:
Here is an IDEONE PHP demo that only echos Matched 'a b'
:
if (preg_match('~^[^\s#+&\'"\\\\]+(?:\s[^\s#+&\'"\\\\]+)*$~', "")) {
echo "Matched ''\n";
}
if (preg_match('~^[^\s#+&\'"\\\\]+(?:\s[^\s#+&\'"\\\\]+)*$~', " ")) {
echo "Matched ' '\n";
}
if (preg_match('~^[^\s#+&\'"\\\\]+(?:\s[^\s#+&\'"\\\\]+)*$~', " a")) {
echo "Matched ' a'\n";
}
if (preg_match('~^[^\s#+&\'"\\\\]+(?:\s[^\s#+&\'"\\\\]+)*$~', "a b")) {
echo "Matched 'a b'\n";
}
if (preg_match('~^[^\s#+&\'"\\\\]+(?:\s[^\s#+&\'"\\\\]+)*$~', "a b")) {
echo "Matched 'a b'\n";
}