[英]Regex condition for extra white spaces between words in a string
^(?=\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
在這里測試
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.