MS Word 中行尾的通配符?
Wild card for end of line in MS Word?
我的匹配模式有 4 个部分:
<1st part><2nd part><3rd part><4th part>
Here,
<1st part> = Fixed string "Fedora"
<2nd part> = A 2 digit number "[0-9][0-9]"
<3rd part> = Followed by a ":" symbol.
<4th part> = one or more strings till the end of the current line.
NOTE : <4th part> ends with the end of current line and contains only alphabets.
我到这里了:
Fedora[0-9][0-9]?[a-z]*[A-Z]*^l>
但是最后一部分——搜索行尾——没有产生预期的结果。请注意,当 Word 自动换行时,我正在尝试获取行尾。
我哪里错了?
在我看来你需要:
查找=Fedora[0-9]{2}:*^l
或:
查找=Fedora[0-9]{2}:*[^l^13]
无法使用 Word 的内置 Find
来定位由 Word 自动布局生成的行的结尾。唯一可以搜索的 "end-of-line" 是通过按 Shift+Enter 插入的手动换行符。手动换行对应特殊查找字符^l
.
如果您需要查找并扩展到行尾,则需要使用宏 (VBA)。以下示例代码可以满足您的需要。请注意,在代码 的情况下 只有最后一次出现的搜索词才会在宏完成时被选中。您需要将您正在寻找的最终结果构建到其中。
或者,只需删除 Do While
和 Loop
行,宏就会找到第一个词。
Sub FindThenToEndOfLine()
Dim r As Range, rDoc As Word.Range
Dim bFound As Boolean
bFound = True
Set r = ActiveDocument.content
Set rDoc = r.Duplicate
r.Find.ClearFormatting
Do While bFound
With r.Find
.text = "Fedora[0-9][0-9]:[a-z]*[A-Z]*"
.Forward = True
.wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
bFound = .Execute
End With
If bFound Then
r.Select
Selection.EndKey Unit:=wdLine, Extend:=True
End If
Loop
End Sub
我的匹配模式有 4 个部分:
<1st part><2nd part><3rd part><4th part>
Here,
<1st part> = Fixed string "Fedora"
<2nd part> = A 2 digit number "[0-9][0-9]"
<3rd part> = Followed by a ":" symbol.
<4th part> = one or more strings till the end of the current line.
NOTE : <4th part> ends with the end of current line and contains only alphabets.
我到这里了:
Fedora[0-9][0-9]?[a-z]*[A-Z]*^l>
但是最后一部分——搜索行尾——没有产生预期的结果。请注意,当 Word 自动换行时,我正在尝试获取行尾。
我哪里错了?
在我看来你需要:
查找=Fedora[0-9]{2}:*^l
或:
查找=Fedora[0-9]{2}:*[^l^13]
无法使用 Word 的内置 Find
来定位由 Word 自动布局生成的行的结尾。唯一可以搜索的 "end-of-line" 是通过按 Shift+Enter 插入的手动换行符。手动换行对应特殊查找字符^l
.
如果您需要查找并扩展到行尾,则需要使用宏 (VBA)。以下示例代码可以满足您的需要。请注意,在代码 的情况下 只有最后一次出现的搜索词才会在宏完成时被选中。您需要将您正在寻找的最终结果构建到其中。
或者,只需删除 Do While
和 Loop
行,宏就会找到第一个词。
Sub FindThenToEndOfLine()
Dim r As Range, rDoc As Word.Range
Dim bFound As Boolean
bFound = True
Set r = ActiveDocument.content
Set rDoc = r.Duplicate
r.Find.ClearFormatting
Do While bFound
With r.Find
.text = "Fedora[0-9][0-9]:[a-z]*[A-Z]*"
.Forward = True
.wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
bFound = .Execute
End With
If bFound Then
r.Select
Selection.EndKey Unit:=wdLine, Extend:=True
End If
Loop
End Sub