Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何编写一个正则表达式来匹配每个单词之间只有一个空格且没有尾随或前导空格的字符串?字符串可以 - 除了字母 - 只包含 [-.,'] 字符并且单词之间没有连续的空格。
"testing 2 regx-tested"
"testing regx#tested "
把你说的写下来
Regex regex = new Regex("[-0-9a-z.,']+( [-0-9a-z.,']+)*");
这应该匹配一个单词,然后是许多其他单词,由一个空格分隔。