SublimeText is a text editor on mac, similar to notepad++ or editplus on windows.

Regular expressions are regular expressions for finding, replacing, etc. text. Details: [] ( Regexp/regexp-intro.html)

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. .

Decomposition description

Those who are familiar with regular expressions should understand it after reading it. Can you take it directly?

Attach some of the original string (copying from the word document becomes the following), it is convenient to test:

Visitors who are not familiar with SublimeText and regulars should look down: (Please be sure to look at the pictures!)

  1. 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):

The 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:

  1. Match a single Chinese character

  1. Match multiple Chinese characters (more than one "+" in the first step, meaning that one or more of the left characters next to "+" can appear)

  1. Match newline characters (\n on linux/mac and \r\n on windows)

Keep an eye out for the "frame" changes around the characters in the editor!

  1. Match a single English character (only the lowercase letters of a-z are actually here)

  1. Match multiple English characters (same reason, add "+" at the end)

  1. Grouping is easy to refer to (not grouped for grouping, it can be referenced when it is convenient to replace)

  1. Reference grouping, complete replacement

Last modified: 2019年3月29日



Write a Reply or Comment

Your email address will not be published.