I used ultraedit in, And I used regular expressions to search for it in. It was also in. I have never studied it in depth. I have been thinking about it several times. But now, the customer gave me a requirement that I can use regular expressions. after half an hour of exploration, I finally started to look at the door, but I was so happy to remember it.
Body:
The customer file is as follows:
....
} Li & quot; (a) | in general.-If T (the latter half is slightly the same as the former one)
} Ls I
} Li & quot; (I) | the percentage d
} Li & quot; (ii) | any increase in
} Li & quot; (B) | Determination
} PG 148
} Ls I
} Li & quot; (I) | the percentage d
} Li & apos; (ii) | the sum of
} Li & quot; (c) | aggregate contra
....
Requirements:
Change & quot; (serial number) | to (serial number) | & quot; serial number to 123 abc I II III ....
Ideas:
First, the regular expression provided for search is very easy to replace the serial number directly with * (all the following searches require the "Regular Expression" option to be checked in the search box of ultraedit). The search expression is as follows:
& Quot; (*) |
A search is successful.
The next step is to solve the problem: how to display the serial number in the replacement box before reading the information to help know that the replacement expression in UE is ^ X, and the range of X is 1-9, but the problem is that I have never known why what about ^ 1 in the expression? Obviously, the first and only annotation expression in my search expression is this *.
Step 1: directly write in the replacement expression
(^ 1) | & quot;
If the replacement is not successful as expected, replace the first & quot; (a) | with () | & quot; that is, ^ 1 has not obtained the value.
Step 2: Crazy ing
Step 3: Check the information and find an online example:
Merge a segment into one row: Replace [^ t] ++ ^ P ^ ([~ ^ T ^ p] ^) is ^ 1
A try is acceptable, but it is not used in it *? Where does wildcard like Ah ^ 1 come from? Surprising studies seem enlightened in the dark
Another sentence was found:
The corresponding replacement expression is ^ X, and the range of X is 1-9. For example, if ^ (H * o ^) ^ (F * s ^) matches "Hello folks", ^ 2 ^ 1 indicates that it will be replaced with "Folks hello.
Aha.The expression in a ^ (^) is a replacement region, that is, the wildcard corresponding to ^ 1 ^ 2!
Step 4: improve search methods
& Quot; ^ (*) ^) |
Replace
(^ 1) | & quot;
Execution discovery & quot; (a) | replaced with (c) | & quot;
Although it is not the result I want, the serial number has already appeared, that is, it is very close to the success. It is also logical to gradually find the final correct conclusion:
Conclusion:
- CTRL + R open the replacement window and check the regular expression Option
- Enter ^ (& quot; ^) ^ (*) ^ (| ^) (red) in the search box)
- Enter ^ 2 ^ 3 ^ 1 (red part) in the replacement box)
- Replace all with OK
Explanation: The Search expression is divided into three parts: ^ (& quot; ^) ^ (*) ^ (| ^). Can you see it?