Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 the dog = true
the  cat  chased  the dog = false (doubles spaces occur at random intervals)

thanks

like image 294
SetiSeeker Avatar asked Nov 23 '25 14:11

SetiSeeker


1 Answers

Try

^((?!\s{2}).)*$

In this expression (?!\s{2}). matches every character except whitespace ones, followed by another whitespace.

like image 52
Jens Avatar answered Nov 26 '25 17:11

Jens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!