-3

これらすべての条件に対して単一の regx 1. 英数字のみを許可する必要があります 2.単語間に 1 つのスペースのみを含める必要があります 3.-.,' などの特殊文字のみを許可する必要があります 4.先頭のスペース、末尾のスペース、および連続する空白スペースを許可しないでください。

有効な入力:

"testing with 2 regx solution"

無効入力:

" testing    with 2 regx solution" or "testing  %^with 2 regx solution "
4

2 に答える 2

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
于 2012-12-06T14:52:50.127 に答える
-1
 inputString= Regex.Replace(inputString.Trim(),@"\s+"," ");

--SJ

于 2012-12-06T14:28:16.547 に答える