Remove the spaces of end of studio visual 2012

advertisements

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!

[\s-[\n]]+\n

...or any whitespace character (\s) except (-) linefeed ([\n]). Ordinarily, - 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.

ref: Character Classes in Regular Expressions