Word 通配符搜索和替换公式元素

Word 通配符搜索和替换公式元素

(vn = vp = 0)

有谁知道是否可以使用通配符在 Word 中搜索和替换,以将規模=峰值

另外,同样的搜索和替换,但是1 =峰值,下标数字不斜体化。

感谢所有回复和解决方案。

彼得

答案1

对的,这是可能的。

确切的语法取决于您想要通配符的内容;这里有一个示例,其中 v 可以是任何字母:

在此处输入图片描述

问号代表单个字母,在替换字符串中,它们会像\1第一个字母和\2第二个字母一样被插入回去,因此无论那里是什么字符,都会保留。请注意,目标格式是“斜体”,因此无论它们是什么格式,替换后它们都会变成斜体。

Format使用和下拉菜单中列出的功能Special,您可以构建所需的内容。请注意,下拉菜单会根据光标所在的位置(源字段或目标字段)进行敏感操作,并分别显示不同的选项。

答案2

对于你的第二个问题,只需从下标数字中删除斜体

在此处输入图片描述

我会逐步执行每个更改(查找下一个)并一次替换一个(替换)而不是(全部替换),以 100% 确保您不会更改下标中的任何其他内容。

答案3

我认为这是迄今为止我发现的最好的参考资料:关联


[如果链接失效,以下是原始网站的文本。]

参考文献(链接中提到):

"Find and replace text and other data in a Word document" @ https://support.office.com/en-us/article/find-and-replace-text-and-other-data-in-a-word-document-c6728c16-469e-43cd-afe4-7708c6c779b7.
"Finding and replacing characters using wildcards" @ https://wordmvp.com/FAQs/General/UsingWildcards.htm.

查找、替换和转到及其快捷键 快捷键 功能 查找 Ctrl-F 查找文本(在“导航”窗格中) 替换 Ctrl-H 查找和替换文本 单击“更多”显示“搜索选项”,例如“匹配大小写”、“仅查找整个单词”、“使用通配符”等。“使用通配符”支持正则表达式 (regex)。 转到 Ctrl-G 与“查找”类似,但允许您搜索非文本对象,例如图形、标题、字段、公式等。 使用插入符号代码查找/替换模式和特殊字符 ^code

Word 允许您使用 ^code 形式的代码来查找/替换文本模式。这些代码是 Word 独有的。

要检查这些代码:Ctrl-H ⇒ “替换”选项卡 ⇒ 将光标放在“查找内容”或“替换为”字段内 ⇒ 更多 ⇒ 特殊 ⇒ 选择所需项目来生成 ^code。

这些代码可用于“查找内容”和“替换为”字段:

^p (Parallel Mark or Newline)(or ^13); ^l (Manual Line Break)(or ^11); ^t (Tab)(or ^9)
^^ (Caret - to resolve ambiguity)
^w (White Space - space or tab)
^nnn (ASCII character in decimal), ^0nnn (ANSI character)

这些代码可以在“查找方式”中使用:

^? (Any Character); ^# (Any Digit); ^$ (Any Letter)
^g (Graphics)

您可以在“替换为”字段中使用这些代码:

^& ("Find What" result text)
^c (Clipboard Content)

举些例子:

"Find what" code: ^#^#%
"Find what" meaning: two digits followed by %.
"Replace with" code: --^&--
Choose "Replace" or "Replace All"
Result: Enclose (next or all) two-digit percent by -- and --.
[TODO]

使用正则表达式 (Regex) 或通配符查找/替换

Word 支持使用其自己的正则表达式(regex)变体(称为通配符)进行查找/替换。

要使用正则表达式:Ctrl-H(查找/替换)⇒选中“更多”下的“使用通配符”选项。

阅读“正则表达式 (Regex)”了解 Regex 的语法。Word 以其独特的方式支持正则表达式!

正则表达式是匹配一组文本字符串的模式。基本正则表达式模式匹配单个字符,如下所示:

Any letter, digit and most of the special characters matches itself. For example, a match a; 9 matches 9; % matches %. In word, the matching is case sensitive, i.e., x matches x but not X. Take note that Word supports Unicode characters in search too.
These special characters have a special meaning: [ ] { } < > ( ) - @ ? ! * \. To match these characters, prepend with the escape character \. For example, \< matches <; \@ matches @.
^nnn: match the ASCII character having decimal number nnn. For example, ^13 matches newline; ^9 matches tab; ^65 matches A; ^97 matches a. This is not standard regex.

用于匹配文本字符串(字符序列)的正则表达式由一系列子模式(或子表达式)组成,例如 xyz 匹配 xyz;12345 匹配 12345;\ 匹配

您可以在匹配中使用以下通配符:

?: matches any single character, including space and punctuation characters. For example, ab?de matches abade, abbde, abXde, etc. (This is not a standard regex and is unique to Word. Standard regex uses dot (.) which matches any single character other than newline).
*: matches any sequence of characters, including space and special characters. For example, a*t matches art, aXXt, a@^@t, a t, etc. (This is not a standard regex, which uses .*)
[ ]: matches one (single) of the characters enclosed (i.e., OR), e.g., [aeiou] matches a, e, i, o or u.
[ - ]: matches any single character in this range, e.g., [a-z] matches any (single) lowercase letter; [a-z0-9] matches any (single) lowercase letter or digit.
[! ]: NOT one of the characters enclosed. For example, [!aeiou] matches any (single) character other than a, e, i, o or u. (This is not standard regex, which uses caret (^).)
{n}, {m,n}, {n,}: occurrence indicators for n, m-to-n, and n-or-more occurrences. For example, abc{2} matches abcabc; ab{2-3} matches abab or ababab.
@: occurrence indicators for one or more occurrences, same as {1,}. For example, abc@de matches abcde, abcabdde, abcabcabcde, etc. (Standard regex uses +. Word does not support * (zero or more), ? (zero or one) used in standard regex. Word also does not support {0,} and {0,1} which is probably a bug?!?!).
<, >: Positional Anchors matching the beginning or ending of a word boundary. For example, <pre matches any word beginning with pre; <apple> matches the word apple; ing> matches any word ending with ing.
( ): Parenthese can be used for two purposes:
    Grouping sub-patterns: e.g., (abc){2} matches abcabc, but abc{2} matches abcc.
    back references: They have no effect in "find" but divide the match result into sub-matches, identified as \1, \2, \3, etc, where \1 is the matched content of the first set of parentheses. For example, <*> <*> matches two words separated by a space without back references. You can set back references using parenthese in this form (<*>) (<*>) to "mark" the two matched words. You can refer to the resultant content of the first matched word as \1, and second word as \2. See more example below.
Word uses "lazy" matching, i.e., it quits matching as soon as the shortest match is found. For examples, xy{2,4} tries to match xyy, then xyyy, and then xyyyy in lazy matching. On the other hand, most Unix tools and programming languages use "greedy" matching to get the longest match.

举些例子:

Objective: Swap two words
"Find what" regex: (<*>) (<*>)
"Find what" meaning: two complete words separated by a space, marked by two parenthesized back references \1 and \2.
"Replace with" regex: \2 \1
"Replace with" meaning: \1, \2 denoted the first and second matched back references.
Choose "Replace" (next 2 words) or "Replace All" (all two consecutive words).
"Find what" regex: ([! ]@)^13
"Find what" meaning: one or more non-space before the paragraph mark - matches the last word or partial word at the end of the paragraph marked by parenthezied back reference \1. This is slightly different from (<*>)^13, which matches a complete word at the end of the paragraph.
Objective: Transposing date from the form "28th March 2018" to the form "March 28, 2018"
"Find what" regex: ([0-9]{1,2})([dhnrst]{2}) (<[ADFJMNOS]*>) ([0-9]{4})
"Replace with" regex: \3 \1, \4
Objective: Transposing date from the form "28/03/2018" to "2018/03/28"
"Find what" regex: ([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})
"Replace with": \3/\1/\2
Objective: Remove empty rows
"Find what" regex: (^13)\1@
"Find what" meaning: Two or more consecutive paragraph marks. Take note that you can use back references in "Find with".
"Replace with" regex: ^p
"Replace with" meaning: In word, you can use ^p in "Replace with", but NOT in "Find what". You need to use ^13 in "Find what".

查找图像、表格、评论和其他对象

按 Ctrl-F 显示“导航”窗格 ⇒ 单击“搜索文档”中的向下箭头 ⇒ 您可以选择“图形”、“表格”、“公式”、“脚注/尾注”或“注释”。转到特定页面、表格、标题或其他项目

Ctrl-G(转到)⇒ 在“转到什么”中,选择项目类型,例如“图形”、“表格”、“标题”、“字段”、“方程式”、“对象”等。查找/替换特定格式

Ctrl-H(查找/替换)⇒查找或替换选项卡⇒更多⇒格式⇒您可以选择各种格式,例如“字体”、“段落”、“样式”等⇒输入文本(可选)。

相关内容