Regex to Exclude Double spaces
I am looking for a regular expression for c# asp.net 3.5 that will fail if there are ever any double spaces in a sentence or group of words.
the cat chased t开发者_运维技巧he dog = true
the cat chased the dog = false (doubles spaces occur at random intervals)
thanks
Try
^((?!\s{2}).)*$
In this expression (?!\s{2}).
matches every character except whitespace ones, followed by another whitespace.
Do you even need to use regexs? Why not try:
string test = "the cat chased the dog";
bool containsDoubleSpaces = test.Contains(" ");
your regexp is just this : " +"
(that's 2 spaces with a + after them)
it will match 2 or more spaces in a row.
^.* .*$
or even
(just two spaces) would do the trick. Replace spaces with \s
if you wish to accomodate any two whitespace charachers in succession (tabs, new lines etc)
精彩评论