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.
On Notepad++, this can be done using
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).
\(escaped space) is to match horizontal space.
\tis to match tab.
[ ](brackets) is for grouping the characters we wanna match.
+is to match 1 or more repetition.
- The dollar sign (
$) is to match the "tail"; any line which ends with it.
Second method: using
\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.
RegExpcontrol characters documentation
Pythonrelated Q&A about trailing white space on Stack Overflow
- "Match whitespace but not newlines (Perl)" Q&A on Stack Overflow
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.