Helpful Information
Home
Categories
Contact us
Category: Regex Programming
Remove more than 2 spaces but keep atleast one
simply want to keep atleast one space out of many, and if atleast one already exists then dont take it out.
e.g.
string:
string string string
Regex:
/\s{2}/
Result:
string stringstring
Expected:
string string string
crap nvm
/\s+/
crap nvm
/\s+/
Note that such a regex will also replace new line characters. To replace 2 or more spaces (or tabs) with a single space, you could do this (in Perl):
$str =~ s/[ \t]{2,}/ /g;
privacy (GDPR)