I want to replace all more than 2 white spaces in a string but not new lines, I have this regex: \s{2,}
but it is also matching new lines.
How can I match 2 or more white spaces only and not new lines?
I'm using c#
I want to replace all more than 2 white spaces in a string but not new lines, I have this regex: \s{2,}
but it is also matching new lines.
How can I match 2 or more white spaces only and not new lines?
I'm using c#
Put the white space chars you want to match inside a character class. For example:
matches 2 or more spaces or tabs.
You could also do:
which matches any white-space char except
\r
and\n
at least twice (note that the capitalS
in\S
is short for[^\s]
).