Microsoft Word Regular Expression
Word裏的正則表達式-不一樣的符號。
一、Normal Find and Replace
二、Search by using wildcards/利用通配符(*)搜索
1、Expressions in wildcards searches
Use parentheses ( ) to create groups of wildcard characters and text in the Find What box, and then use
in the Replace With box to use the results of each expression.
用括号()在Find What输入框中去创建包含wildcard字符和文本的分组,然后在Replace With输入框中用
去代替每个表达式。注意:n是 分组/group 的序号。比如有5个(,即创建了5格分组,则n可以是是1至5中的任意一个值。
You can use the
wildcard to search for an expression and then replace it with the rearranged expression. For example, type (Ashton) (Chris) in the Find what box and 2 1 in the Replace with box. Word will find Ashton Chris and replace it with Chris Ashton.
可以利用
通配符去搜索一个表达式,并用重新排序的表达式替换。比如在Find what框中输入(Ashton) (Chris),在Replace with框中输入2 1。Word会搜索Ashton Chris,并用Chris Ashton去替换,也就是说:将第2组与第1组交换顺序。
2、Wildcards for items you want to find and replace/常用 wildcard/通配符
- When the Use wildcards check box is selected, Word finds only the exact text that you specify. Notice that the Match case and Find whole words only check boxes are unavailable (dimmed) to indicate that these options are automatically turned on. You can't turn off these options.
- To search for a character that's defined as a wildcard, type a backslash () before the character. For example, type ? to find a question mark or to find a backslash character (this is often called an “escape character”).用 backslash/反斜线,即在字符前加一个反斜线(),来搜索 通配符/wildcard。比如输入 ?来搜索 ?/问号。
- You can use parentheses to group the wildcard characters and text and to indicate the order of evaluation. For example, type <(pre)*(ed)> to find "presorted" and "prevented".利用()/英文括号将通配符和文本分组。
To find | Type | Example |
---|---|---|
Any single character, including space and punctuation characters | ? | s?t finds sat, set, and s t. |
One of these characters | [ ] | w[io]n finds win and won. |
Any single character in this range | [-] | [r-t]ight finds right, sight,tight. Ranges must be in ascending order. |
The beginning of a word | < | <(inter) finds interesting and intercept, but not splintered. |
The end of a word | > | (in)> finds in and within, but not interesting. |
Expression | () | Word remembers the results of a search combination to use in a replace operation. |
Any single character except the characters in the range inside the brackets | [!x-z] | t[!a-m]ck finds tock and tuck, but not tack or tick. |
Exactly n occurrences of the previous character or expression | {n} | fe{2}d finds feed but not fed. |
At least n occurrences of the previous character or expression | {n,} | fe{1,}d finds fed and feed. |
From n to m occurrences of the previous character or expression | {n,m} | 10{1,3} finds 10, 100, and 1000. |
One or more occurrences of the previous character or expression | @ | lo@t finds lot and loot. |
Any string of characters, including space and punctuation characters | * | s*d finds sad, started, and significantly altered. |
注意:上边的这个表格使用Cnblog的Markdown编辑器自动生成的,暂时不知道如何设置表格的属性-文本对齐、换行。
三、Use codes to find letters, formatting, fields, or special characters
1、Code that work in the Find What box or Replace With box.
To find | Type |
---|---|
Paragraph mark ( ¶) | ^p (doesn't work in the Find what box when the Use wildcards option is turned on), or ^13 |
Tab character ( tab character ) | ^t or ^9 |
ASCII character | ^ nnn, where nnn is the character code |
ANSI character | ^0 nnn, where 0 is zero and nnn is the character code |
Em dash (—) | ^+ |
En dash (–) | ^= |
Caret character | ^^ |
Manual line break ( manual line break ) | ^l or ^11 |
Column break | ^n or ^14 |
Page or section break | ^12 (when replacing, inserts a page break) |
Manual page break | ^m (also finds or replaces section breaks when the Use wildcards option is turned on) |
Nonbreaking space ( nonbreaking space ) | ^s |
Nonbreaking hyphen ( nonbreaking hyphen ) | ^~ |
Optional hyphen ( optional hyphen ) | ^- |
四、Find and replace text by using regular expressions (Advanced)
1、About Regular Expression
You can automate many find-and-replace tasks by using wildcard characters to build regular expressions, which are combinations of literal text and wildcard characters. The literal text characters indicate text that must exist in the target string of text. The wildcard characters indicate the text that can vary in the target string. For example, you can use regular expressions to find and remove duplicate rows from a large table or to transpose a list of names (change them from "First Last" to "Last, First").
2、
參考: