Monkey Raptor

Monday, October 26, 2015

Notepad++: Matching Trailing Horizontal White Space

Sometimes, we wanna trim our application codes. So that it'll have no extra trailing horizontal white spaces.

Trailing white space is

any spaces or tabs after the last non-whitespace character on the line until the newline.

stackoverflow.com/a/21410096

On Notepad++, this can be done using RegExp.


Standard method: matching space and/or tab character

The snippet above will match 1 or more repetition of trailing horizontal white space (the space and/or tab).

Details:

  • The (escaped space) is to match horizontal space.
  • The \t is to match tab.
  • The [ ] (brackets) is for grouping the characters we wanna match.
  • The + is to match 1 or more repetition.
  • The dollar sign ( $ ) is to match the "tail"; any line which ends with it.

Second method: using Perl flavored RegExp

Since Notepad++ is super neat, therefore we can use:

The \h is to match horizontal white space (space and/or tab).

This second method is shorter and will yield the same matching characters as the first method.


How to use the RegExp for search on Notepad++

On Windows, the shortcut to open the search dialog is ctrl + f. Then tick the Regular expression option.

To delete all trailing horizontal white space, type either snippet above for the Find what input ► switch the search dialog to Replace ► empty the Replace with input ► hit Replace All.


Links


On Notepad++ version something, around above this version (I didn't look at the version of this post), we can use ALT + SHIFT + S to automatically trim the trailing space and save our work.
Notepad++: Matching Trailing Horizontal White Space
https://monkeyraptor.johanpaul.net/2015/10/notepad-matching-trailing-horizontal.html

No comments

Post a Comment

Tell me what you think...