I want to remove trailing spaces of each line from a text file, keeping the line breaks intact. I am using Visual studio 2012's Regex feature for this.
When I am trying to find
\s*\r?\n and replace with
\r\n it is also stripping out all the empty lines, which is not expected.
Is there anything that I am missing?
Set subtraction to the rescue!
...or any whitespace character (
\s) except (
-) linefeed (
- is treated as either a range operator or a literal hyphen (depending on its position within the character class), and
[ is treated as a literal bracket. But if the hyphen is followed by something that looks like a character class, it becomes a set subtraction operator.