Skillfully using EDITPLUS regular expression to delete redundant blank lines in documents

Time:2021-12-4

Most of the articles collected from the Internet have a large number of redundant blank lines, which occupy a lot of space. If you need to print, it will be a waste of paper. You want to delete these blank lines, but they either do not contain any characters or contain many spaces and tabs. If the article is relatively long, manually deleting empty lines will become a very laborious thing. Is there no other way? Of course!

We can implement it with the help of text editor software EDITPLUS and UltraEdit. EDITPLUS and UltraEdit are common sharing software. Almost all software download websites provide downloads. Because EDITPLUS is easier to operate, but UltraEdit is more commonly used, this article first introduces the operation in EDITPLUS, and then UltraEdit.

1、 Delete empty lines in EDITPLUS

Start EDITPLUS and open the pending file. Note that it must be a plain text file. If it is a word document, you need to paste it into the plain text file first. Then, the steps are as follows:

1. Select replace from the search menu to display the text replacement dialog box as shown in the figure. Selecting the regular expression check box indicates that we want to use regular expressions in search and replacement. Then, select “current file” in “replace all range” to indicate the operation on the current file. (tip: you can open multiple files at the same time, as long as you select “all open files”).

2. Click the button on the right side of the “find content” combo box to open the drop-down menu, as shown in the following figure. Among the menu commands, the commands used in this paper are: tab, line feed, characters in range, line beginning, 0 or multiple matches.

The following operation adds a regular expression that represents the empty row to be found. (tip: empty lines only include space character, tab character and carriage return character, and must start with one of these three symbols and end with carriage return character. The key to finding empty lines is to construct regular expressions representing empty lines).

(1) If “line beginning” is selected, the character “^” appears in the search content combo box, indicating that the string to be searched must appear at the beginning of a line in the text to meet the conditions.

(2) Select “characters in range”, add a pair of brackets “[]” after “^”, and the current insertion point is in brackets. Parentheses are expressed in regular expressions. If the characters in the text match any character in the parentheses, they meet the search criteria.

(3) Click the spacebar to add a space character. A space character is a component of a blank line.

(4) Select tab and add a “\ T” representing the tab.

(5) Move the cursor, move the current insertion point after “]”, then select “0 or more matches”, and add the asterisk character “*”. The asterisk indicates that the space character or tab character in the bracket “[]” before it appears 0 or more in a row.

(6) Select “line feed” and insert “\ n”, indicating carriage return.

So far, the regular expression is constructed successfully (as shown in the figure below).

3. The replacement content combo box remains empty, indicating that the found content is deleted. Click Replace to delete empty lines one by one, or click replace all to delete all empty lines (Note: EDITPLUS and UltraEdit both have the problem that replacing all can not completely delete empty lines at one time, which may be a program bug and need to press the button several times).

For those who are familiar with EDITPLUS, you can directly enter the regular expression in find what^[ \t]*\n Note that there is a space character before \ t.

Note: it doesn’t work in auto line feed mode. Just change it to no auto line feed.

1) Menu: Edit – > Select – > column select
2) First press Alt + C, release, and then move the mouse or keyboard up, down, left and right to select
 

2、 Delete empty lines in UltraEdit

The principle of using UltraEdit is the same, but UltraEdit does not provide menu mode, so regular expressions need to be entered manually, and the regular expression symbol of UltraEdit is different from EDITPLUS.

After opening the file with UltraEdit, select the replace command in the search menu. In the Replace dialog box, select the regular expression check box and enter in find what:%[ ^t]++^p, notice the space before ^ t. The character meaning of this expression corresponds to that of EDITPLUS. Then, click the start or replace all button to replace and delete empty lines.

2. Click the button on the right side of the “find content” combo box to open the drop-down menu, as shown in the following figure. Among the menu commands, the commands used in this paper are: tab, line feed, characters in range, line beginning, 0 or multiple matches.

The following operation adds a regular expression that represents the empty row to be found. (tip: empty lines only include space character, tab character and carriage return character, and must start with one of these three symbols and end with carriage return character. The key to finding empty lines is to construct regular expressions representing empty lines).

(1) If “line beginning” is selected, the character “^” appears in the search content combo box, indicating that the string to be searched must appear at the beginning of a line in the text to meet the conditions.

(2) Select “characters in range”, add a pair of brackets “[]” after “^”, and the current insertion point is in brackets. Parentheses are expressed in regular expressions. If the characters in the text match any character in the parentheses, they meet the search criteria.

(3) Click the spacebar to add a space character. A space character is a component of a blank line.

(4) Select tab and add a “\ T” representing the tab.

(5) Move the cursor, move the current insertion point after “]”, then select “0 or more matches”, and add the asterisk character “*”. The asterisk indicates that the space character or tab character in the bracket “[]” before it appears 0 or more in a row.

(6) Select “line feed” and insert “\ n”, indicating carriage return.

At this point, the regular expression is constructed successfully.

3. The replacement content combo box remains empty, indicating that the found content is deleted. Click Replace to delete empty lines one by one, or click replace all to delete all empty lines (Note: EDITPLUS and UltraEdit both have the problem that replacing all can not completely delete empty lines at one time, which may be a program bug and need to press the button several times).

For friends familiar with EDITPLUS, you can directly enter the regular expression ^ [\ t] * \ n in find what. Note that there is a space character before \ t.