^(?=\S)^[ `\'\.\-&A-Za-z0-9u00C0-u017F]+(?<=\S)$
这是我想出的,但我不知道如何检查字符串中间单词之间的空格
最佳答案
您不想要的:前导或尾随空格或单词之间的额外空格。 那么您需要一个由单个空格分隔的单词组成的字符串。
我将继续 ^\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
关于java - 字符串中单词之间额外空格的正则表达式条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54420084/