Reputation: 529
How can I replace all the lines in my code that contain only spaces and/or tabs with empty lines?
Example:
for(var l=0,leng=one.codes.length;l<leng;l++){
******
var oneCode = one.codes[l];
var temp = new Object();
******
temp.code = oneCode.c;
******
if(two >= 1000){
var alex = "";
var bob = 0;
}
******
}
The * symbols are the spaces and tabs. I want them removed without changing the rest of the code format. I want this lines to remain blank but without containing any characters.
Upvotes: 3
Views: 3701
Reputation: 6209
^\s+$
in the Find what text fieldUpvotes: 2
Reputation: 627190
You may use
^\h+$
where:
^
- start of the line\h+
- one or more horizontal whitespace symbols$
- end of lineNote: to also remove the line breaks, add a \R*
- zero or more line breaks - at the end of the pattern.
VVVV
Upvotes: 4
Reputation: 522301
You can use the following find and replace:
Find:
(?![^\s]).(\r?\n)
Replace:
$1
This regex uses a negative lookahead, which will assert that at each point in the line the character which follows is not anything but whitespace (including space and tab).
The \r?\n
end of the regex will match either \r\n
, which is the Windows line ending, or just \n
, which is the Unix line ending. This is captured in $1
and then used as the replacement, since you want to keep the line, while removing all whitespace.
Upvotes: 2