所有这些条件的单一套餐 1.应该只允许使用aphanumeric 2.单词之间只有一个空格 3.应该只允许特殊字符,如 - 。,' 4.不应允许前导空格,尾随空格和连续空格。
有效输入:
"testing with 2 regx solution"
输入无效:
" testing with 2 regx solution" or "testing %^with 2 regx solution "
答案 0 :(得分:6)
试试这个
^(\w+\s)*\w+$
^ Start of string ( Start of group \w+ Word of one or more characters \s White space ) End of group * Zero or more of the preeceding group \w+ Word of one or more characters $ End of string
答案 1 :(得分:-1)
inputString= Regex.Replace(inputString.Trim(),@"\s+"," ");
- SJ