SublimeText is a text editor on mac, similar to notepad++ or editplus on windows.
Received a small demand today, you need to update the country, province, city and other values in the left word document in the figure to the right format:
The demand is not that hard, but I feel that writing a separate program for this conversion is a bit of a killer!
Then, just think of a way to get it directly in the text editor!
The gif image may be a bit big, please be patient. .
Those who are familiar with regular expressions should understand it after reading it. Can you take it directly?
Matching regular: ([^\x00-\xff]+)\n([a-zA-Z]+) Replace with: country.$2=$1\n (the end of the \n can be used here) Match blank lines: ^(\s*)\n Replace with: (empty, nothing is entered)
Attach some of the original string (copying from the word document becomes the following), it is convenient to test:
不丹 bt 东帝汶 tl 中国 cn 中非 cf 丹麦 dk 乌克兰 ua 乌兹别克斯坦 uz 乌干达 ug 乌拉圭 uy 乍得 td
Visitors who are not familiar with SublimeText and regulars should look down: (Please be sure to look at the pictures!)
- sublime text editor operation
Note that after opening the replacement action bar, remember to mark the place below the arrow (this means that the regular mode is enabled):
Find What column is the regularity of the string to match, and the
Replace With column is the regular to replace "Yes".
Regular disassembly instructions:
Matching regular: ([^\x00-\xff]+)\n([a-zA-Z]+) Replace with: country.$2=$1
- Match a single Chinese character
- Match multiple Chinese characters (more than one "+" in the first step, meaning that one or more of the left characters next to "+" can appear)
- Match newline characters (
\non linux/mac and
Keep an eye out for the "frame" changes around the characters in the editor!
- Match a single English character (only the lowercase letters of a-z are actually here)
- Match multiple English characters (same reason, add "+" at the end)
- Grouping is easy to refer to (not grouped for grouping, it can be referenced when it is convenient to replace)
- Reference grouping, complete replacement