EditPlus Regular substitution expression (selected text substitution)

Source: Internet
Author: User

EditPlus to find replacements for regular expression applications

Expression description
\ t tab.
\ n New Line.
. matches any character.
| Matches the left and right characters of an expression. For example, "AB|BC" matches "AB" or "BC".
[] matches any single character in the list. For example, "[AB]" matches "a" or "B". "[0-9]" matches any number.
[^] matches any single character outside the list. For example, "[^ab]" matches characters other than "a" and "B". "[^0-9]" matches any non-numeric character.
* The characters on the left are matched at any time (0 or more times). For example, "be*" matches "B", "Be" or "bee".
+ its left character is matched at least once (1 or more times). For example, "be+" matches "be" or "bee" but does not match "B".
? The characters on the left are matched 0 or 1 times. For example, "be?" matches "B" or "be" but does not match "bee".
^ The expression on its right is matched at the beginning of a line. For example, "^a" matches only lines that begin with "A".
contentnbsp; The expression on its left side is matched at the end of a line. For example "Econtentquot; Matches only lines that end with "E".
() affects the order in which the expression is matched and is used as the grouping token for the expression.
\ escape character. If you want to use "\" itself, you should use "\ \".
Regular Expression application--delete blank line ^[\t]*\n
The grouping of expressions is used () to mark. The grouping of expressions can be referred to as \1, \2, \3, and so on. The \ = All string that is matched. \1 represents the first grouping that is matched, \2 represents the second grouping, and so on. Examples are as follows.

Original search Replace Result
ABC (AB) (c) \0-\1-\2 abc-ab-c
ABC A (b) (c) \0-\1-\2 abc-b-c
ABC (a) b (c) \0-\1-\2 abc-a-c

"1" Regular expression application--replace the specified content to the end of the line
The original text, such as the following two lines
ABC AAAAA
123 ABC 444

If you want to encounter "ABC" each time, replace "ABC" with "ABC EFG" After the end of the line
That is, the text above is eventually replaced by:
ABC EFG
123 ABC EFG

Solve:
① in the Replace dialog box, enter "abc.*" in the Find content
② also tick the "Regular expression" checkbox, then click the "Replace All" button
Among them, the meanings of the symbols are as follows:
"." = match any character
"*" = match 0 or more times

Note: In fact, is the regular expression substitution, here is just some of the questions that have been asked to sort out, simply from the regular expression itself, you can derive thousands of special cases.

"2" Regular expression application--digit substitution
Want to put
Asdadas123asdasdas456asdasdasd789asdasd
To be replaced by:
Asdadas[123]asdasdas[456]asdasdasd[789]asdasd

In the Replace dialog box, tick the "Regular expression" check box;
Enter "[0-9][0-9][0-9]" inside the lookup, without quotation marks
"Replace with:" Enter "[\0\1\2]", without quotation marks
Range is the range you are manipulating, and then select Replace.

In fact, this is also a special case of regular expressions, "[0-9]" means matching any special case between 0~9, the same "[A-z]" means matching any special case between a~z
"[0-9]" is reused above, representing three consecutive digits.
"X" represents the first "[0-9]" corresponding prototype, "\1" represents the second "[0-9]" corresponding prototype, and so on
"[", "]" is a simple character, which means add "[" or "]", and if you enter "other \0\1\2", the result is:

Asdadas Other 123 Other Asdasdas other 456 other ASDASDASD other 789 other ASDASD

Feature enhancements (by JIUK2K):
If the Find content "[0-9][0-9][0-9]" is changed to "[0-9]*[0-9]", corresponding to 1 or 123 or 12345 or ...
You can customize it as needed

There are a lot of related content, you can refer to the syntax of regular expressions to study carefully

"3" Regular expression application--deletes the specified character at the end of each line
Because these characters are also present in the line, they must not be implemented with a simple substitution.
Like what
12345 1265345
2345
Need to delete "345" at the end of each line
This is also the use of regular expressions, in fact, it should be relatively simple to look at regular expressions, but since there is this problem, it is suggested that the regular expression has to have a cognitive process, the solution is as follows
Solve:
In the Replace dialog box, enable the Regular Expressions check box
In the Find content, enter "345contentrdquo;
Here "contentrdquo;" indicates a match from the end of the line

If it is matched from the beginning of the line, it can be implemented with "^", but EditPlus has another function that can easily delete the string at the beginning of the line
A. Select the row to manipulate
B. Edit-format-delete line comment
C. In the pop-up dialog box, enter the beginning character to clear, and confirm

"4" Regular expression application--replacing multiple lines with half-width brackets
Hundreds of pages have the following code:
\ n
When the "Regular expression" option is enabled in the Replace dialog box, you are ready to replace the

"5" Regular expression application--delete empty rows
Start EditPlus, open the text type file you want to work with.
①, select the Replace command on the Find menu to pop up the text Replacement dialog box. Select the Regular expression check box to indicate that we want to use regular expressions in Find, replace. Then, select Current file in replace range to indicate the operation for the current file.
②, click the button to the right of the Find what combo box, and a drop-down menu appears.
③, the following action adds a regular expression that represents a blank line to be found. (Tip: Empty lines include only space characters, tabs, carriage returns, and must start with one of these three symbols as a line, and end with a carriage return, the key to finding a blank line is to construct a regular expression that represents a blank line).
Enter the regular expression "^[\t]*\n" directly in "find" and note that there is a space character before \ T.
(1) Select "Start from the beginning of the line", the "Find what" combo box appears the character "^", indicating that the string to be found must appear in the text at the beginning of a row.
(2) Select "character in range", then "^" will add a pair of parentheses "[]", the current insertion point in parentheses. The parentheses are represented in the regular expression, and the characters in the text match any one of the characters in the parentheses to meet the search criteria.
(3) Click the SPACEBAR to add a space. A space character is a constituent component of a blank line.
(4) Select "tab" to add "\ t" that represents the tab.
(5) Move the cursor, move the current insertion point to "]", and then select "Match 0 or more" to add the asterisk character "*". An asterisk indicates that there are 0 or more spaces or tabs in the front of the brackets "[]", in one row.
(6) Select "Line Break" and insert "\ n" to indicate carriage return.
The ④, replace with combo box remains empty, indicating that the found content is deleted. Click the Replace button to delete empty rows row by line, or click the Replace All button to remove all empty rows (Note: EditPlus Sometimes there is a "replace all" can not completely remove the empty line at once, it may be a program bug, you need to press the button more than a few times).

EditPlus Regular substitution expression (selected text substitution)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.