字符串中单词之间额外空格的正则表达式条件

Regex condition for extra white spaces between words in a string

^(?=\S)^[ `\'\.\-&A-Za-z0-9u00C0-u017F]+(?<=\S)$

这是我想出的,但我不知道如何检查字符串中间单词之间的空格

您不想要的:前导或尾随白色 space 或单词之间额外的白色 space。 然后你想要一个由单个白色 space 分隔的单词组成的字符串。

我会继续^\S+(?:\s\S+)*$

详情:

^      # Matches at the beginning of the string
\S+    # Matches one or more non-spacing character
(?:    # Starts a non-capturing group
  \s   # Matches one spacing character
  \S+  # Matches one or more non-spacing character
)*     # Repeat non-capturing group zero or more times
$      # Matches at the end of string

测试here