In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how notepad++ regular expressions replace strings. I hope you will learn a lot after reading this article. Let's discuss it together.
Then the expression is a query string, it contains general characters and some special characters, special characters can expand the ability to find strings, the role of regular expressions in finding and replacing strings can not be ignored, it can improve work efficiency.
EditPlus search, replace, and find in files support the following regular expressions:
The expression describes the / t tab. / n new line. . Match any character. | matches the characters on the left and right of the 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 character on its left is matched any number of times (0 or more times). For example, "be*" matches "b", "be" or "bee". + the character on its left is matched at least once (1 or more times). For example, "be+" matches "be" or "bee" but not "b". ? The character on the left is 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" only matches lines that start with "A". The expression to the left of $is matched at the end of the line. For example, "e $" only matches lines that end with "e". () affects the order in which expressions are matched and is used as a grouping tag for expressions. / escape character. If you want to use "/" itself, you should use "/".
Example:
Original string str [1] abc [991]; str [2] abc [992]; str [11] abc [993]; str [22] abc [994]; str [11] abc [995]; str [1111] abc [996]; str [1111] abc [997]; str [2222] abc [999]; Target string: abc [1]; abc [2]; abc [11]; abc [22]; abc [1111]; abc [222a]; abc [1111]; abc [2222]
Deal with:
Search string: str/ [([0-9] +) /] abc/ [[0-9] + /]
Replacement string: abc [/ 1]
1. The line containing "hello word"
^. * hello word.*$
2. Lines starting with "hello word"
^ hello word.*$
3. Lines ending with "hello word"
. * hello word$
To be replaced by:
Find the target\ n ([a-zA-Z0-9])
Or\ r ([a-zA-Z0-9])
Replace the target $1 (the newline in front of http becomes',', and then add others)
[1] regular expression application-- replaces the specified content to the end of the line
The original text looks like the following two lines
Abc aaaaa
123 abc 444
Every time you want to encounter "abc", replace "abc" and then the content at the end of the line is "abc efg"
That is, the above text is finally replaced by:
Abc efg
123 abc efg
Resolve:
① is in the replace dialog box. Enter "abc.*" in the search content.
② also check the regular expression check box, and then click the replace all button
The meaning of the symbol is as follows:
"." = matches any character
"*" = match 0 or more times
Note: in fact, it is the replacement of regular expressions. Here we just sort out some of the questions that have been raised. Thousands of special cases can be derived simply from the regular expressions themselves.
[2] regular expression application-- numerical substitution
Hope to put
Asdadas123asdasdas456asdasdasd789asdasd
To be replaced by:
Asdadas [123] asdasdas [456] asdasdasd [789] asdasd
In the replace dialog box, check the regular expression check box
Enter "[0-9] [0-9] [0-9]" in the search, without quotation marks
"to be replaced by:" enter "[/ 0 UniUniverse 2]" without quotation marks.
The scope is the scope of your operation, and then choose to replace it.
In fact, this is also a special case of the use of regular expressions. "[0-9]" means to match any special case between 0,9, and "[amurz]" means to match any special case between aquiz.
"[0-9]" is repeatedly used above to indicate three consecutive numbers.
"/ 0" represents the prototype of the first "[0-9]", "/ 1" represents the prototype of the second "[0-9]", and so on.
"[", "]" is a simple character, which means to add "[" or "]". If you enter "other / 0ram 1and2 other", the replacement result is:
Asdadas other 123 other asdasdas other 456 other asdasdasd other 789 other asdasd
Feature enhancement (by jiuk2k):
If you change the search content "[0 # 9] [0 # 9] [0 # 9]" to "[0 # 9] * [0 # 9]", corresponding to 1 or 123 or 12345 or …
Please customize it according to your needs.
There is still a lot of related content. You can study it carefully with reference to the syntax of regular expressions.
[3] regular expression application-deletes the specified character at the end of each line
Because these characters also appear on the line, it certainly cannot be implemented with a simple substitution.
such as
12345 1265345
2345
"345" at the end of each line needs to be deleted.
This is also the use of regular expressions, in fact, it should be relatively simple to take a closer look at regular expressions, but since this problem has been raised, it shows that there must be a process of understanding regular expressions, and the solutions are as follows
Resolve:
In the replace dialog box, turn on the regular expression check box
Enter "345 $" in the search.
Where "$" means to match from the end of the line
If you match from the beginning of a line, you can do it with "^", but EditPlus has another feature that can easily delete the string at the beginning of a line.
a. Select the row to be operated on
b. Edit-format-delete line comments
c. Enter the first character of the line to be cleared in the pop-up dialog box and make sure
[4] regular expression application-- replace multiple lines with half-angle parentheses
Hundreds of web pages have the following code:
/ n
Enable the regular expression option in the replace dialog box, and you can complete the replacement.
[5] regular expression application-delete blank lines
Start EditPlus and open the text type file to be processed.
①, choose the replace command of the find menu, and the text replacement dialog box pops up. Selecting the regular expression check box indicates that we want to use regular expressions in finding and replacing. Then, select current File in the replace scope to indicate the operation on 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 the blank line to be found. Tip: blank lines include only spaces, tabs, and carriage returns, and must begin with one of these three symbols and end with a carriage return. The key to finding blank lines is to construct regular expressions that represent blank lines.
Enter the regular expression "^ [/ t] * / n" directly in find, and notice that there is a space character before / t.
(1) Select "match from the beginning of the line", and the character "^" appears in the "find what" combo box, indicating that the string to be found must appear at the beginning of a line in the text.
(2) Select "character in range", then a pair of parentheses "[]" will be added after "^", and the current insertion point is in parentheses. Parentheses indicate in a regular expression that the characters in the text match any one of the parentheses to meet the search criteria.
(3) Click the space bar to add a space character. A space character is a component of a blank line.
(4) Select "Tabs" and add "/ t" representing tabs.
(5) move the cursor, move the current insertion point after "]", and then select "match 0 times or more", which adds the asterisk character "*". An asterisk indicates that there are 0 or more spaces or tabs in parentheses "[]" in front of them.
(6) Select "newline" and insert "/ n" to indicate the carriage return.
The ④ and replace with combo boxes remain empty, which means that what is found is deleted. Click the "replace" button to delete blank lines line by line, or click the "replace all" button to delete all blank lines (note: EditPlus sometimes has the problem that "replace all" can not completely delete blank lines at one time, may be the program BUG, need to press the button several times).
1. In Sinicization, do you often encounter such sentences that need to be translated:
Code:
"Error adding the post!"
"Error adding the comment!"
"Error adding the user!"
If there are a lot of similar documents, a translator is obviously tired and boring.
You can actually do this by using the substitution function in Editplus and selecting the regular expression check box in the replacement dialog box:
Find the original file:
Code:
"Error adding ([^! |" |;] *)
To be replaced by:
Code:
"an error occurred while increasing / 1
What happens after this replacement? The result is:
Code:
"an error occurred while adding the post!"
"an error occurred while adding the comment!"
"an error occurred while adding the user!"
Ok, what will you do next? Of course, replace the post, the comment and the user with the words you want to translate. Get the final result:
Code:
"an error occurred while adding posts!"
"an error occurred while adding comments!"
"an error occurred while adding users!"
two。 The words to be extracted are in the middle, such as:
Code: can not be deleted because can not be added because can not be updating because
You can do this in this way:
To use the replace function in Editplus, select the regular expression check box in the replace dialog box:
Find the original file:
Code:
Can not be ([^] *) because
To be replaced by:
Code:
Cannot be / 1 because
What happens after this replacement? The result is:
Code:
Can't be deleted because
Can't be added because
Can't be updating because
The remaining steps are as above.
In the case of a large amount of Sinicization and monotonous sentence patterns, the improvement of efficiency is obvious!
Explain: ([^! | "|;] *) means that it is not equal to! and any one of" and; "means that all characters except these three characters will be selected (replacement area).
/ 1 is the new location of the selected replacement area (copied to this new location).
3. Often manually clean up the blank lines in the text file line by line, which can actually be better done by Editplus. Use the replacement function in Editplus, and select the "regular expression" check box in the replacement dialog box:
Find the original file:
Code:
^ [/ t] * / n
If the replacement part is blank, you can delete the blank line and execute it to see:)
Abandon [2''b9nd2n] v. abandon, abandon
Abandonment [2''b9nd2nm2nt] n. Give up
Abbreviation [2bri: vi''ei62n] n. Abbreviation
Abeyance [2''bei2ns] n. Hold over
Abide [2''baid] v. comply with
Ability [2''biliti] n. Capability
Able [''eibl] adj. Capable
Abnormally [9b''n0:m2l] adj.
Aboard [2''b0:d] adv. Ship (car)
1.
Find: (^ [a-zA-Z0-0swap -] +) (/ [*. * /] +) (. *)
Replace: @ "/ 1", "/ 2", "/ 3"
Effect:
@ "abandon", "[2''b9nd2n]", "v. abandon, give up"
@ "abandonment", "[2''b9nd2nm2nt]", "n. Abandon"
@ "abbreviation", "[2bri:vi''ei62n]", "n. Abbreviation"
@ "abeyance", "[2''bei2ns]", "n. Suspend, abort"
@ "abide", "[2''baid]", "v. comply"
@ "ability", "[2''biliti]", "n. Ability"
@ "able", "[''eibl]", "adj. Capable, capable"
@ "abnormal", "[9b''n0:m2l]", "adj. Abnormal, abnormal"
@ "aboard", "[2''b0:d]", "adv. Ship (car)"
two。
Find: / n
Replace:
Note: the content to be replaced is empty.
Effect:
@ "abandon", "[2''b9nd2n]", "v. Abandon ", @" abandonment "," [2''b9nd2nm2nt] "," n. Abandon ", @" abbreviation "," [2bri:vi''ei62n] "," n. Abbreviations ", @" abeyance "," [2''bei2ns] "," n. Suspension ", @" abide "," [2''baid] "," v. Obey ", @" ability "," [2''biliti] "," n. Ability ", @" able "," [''eibl] "," adj. Capable, capable ", @" abnormal "," [9b''n0:m2l] "," adj. Abnormal, abnormal ", @" aboard "," [2''b0:d] "," adv. Ship (car) ", @" abolish "," [2''b0li6] "," v. Cancel ", @" abolition "," [9b2''li62n] "," n. To repeal or cancel. "
3.
Find: @
Replace: / n
Effect:
"abandon", "[2''b9nd2n]", "v. abandon, abandon"
"abandonment", "[2''b9nd2nm2nt]", "n. Abandon"
"abbreviation", "[2bri:vi''ei62n]", "n. Abbreviation"
"abeyance", "[2''bei2ns]", "n. Hold over, abort"
"abide", "[2''baid]", "v. comply"
"ability", "[2''biliti]", "n. Ability"
"able", "['eibl]", "adj. Capable, capable"
"abnormal", "[9b''n0:m2l]", "adj. Abnormal"
"aboard", "[2''b0:d]", "adv. On board"
"abolish", "[2''b0li6]", "v. repeal, cancel"
4. Mission accomplished
Delete blank lines (excluding blank lines with space symbols)
1.\ r\ nescape character replacement
Press ctrl+h, jump out of the search replacement box and define the search pattern as an extension (\ n,\ r.)
Find the target:\ r\ n\ r\ n
To be replaced by:\ r\ n
Readers with basic programming skills should know what it means.
2. Textfx plug-in
First select to delete part of the text content, if it is the entire file, then select Ctrl+A, and then use the Textfx plug-in that comes with Notepad++, find Delete Blank Lines in the long list, and click on it.
Note that Notepad++ 's regular expressions are not compatible with escape characters, and so on, so they are more limited and cannot be replaced directly with regular expressions.
Delete blank lines with spaces
1. Delete the space first, then delete the blank line
How do I delete spaces with only space lines?
Find Blank Operations (Line Editor) in the menu edit, click remove line trailing white space, and then delete the blank line using the method above.
2. Use regular expressions to delete spaces in blank lines
Find pattern in replacement select the regular expression ^ + $, replace it with blank (that is, nothing), and then delete the blank line using the method above.
After reading this article, I believe you have some understanding of how notepad++ regular expressions replace strings. If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 243
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.