检查字符串是否包含 2 个空格(但不是一个接一个)


Check if string contains 2 spaces (but not one after the other)

您将如何检查字符串是否在 PHP 中正好包含 2 个不相邻的空格?

f.e. '约翰·韦恩·华盛顿' -> TRUE(字符串中的 2 个空格);"约翰·韦恩" -> 假(1 个空格)

任何带有解释的正则表达式模式?

$string = "Bush      sucks       big    time";
$counter = count_chars($string,0);
echo $counter[32] . " spaces in the phrase.";

使用此模式:

^[^ ]* [^ ]+ [^ ]*$

它匹配一个正好有 2 个不相邻空格的字符串。