MS Word中行尾的通配符?

时间:2018-09-28 10:50:24

标签: ms-word wildcard

我的比赛模式包括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自动换行时,我试图到达该行的结尾。

我要去哪里错了?

2 个答案:

答案 0 :(得分:1)

无法使用Word的内置Find来定位由Word的自动布局生成的行的结尾。唯一可以搜索的“行尾”是按Shift + Enter插入的手动换行符。手动换行符对应于特殊的“查找”字符^l

如果需要查找并扩展到行尾,则需要使用宏(VBA)。以下示例代码可以满足您的需求。请注意,使用宏代码原样,当宏结束时,只会选择最后一次出现的搜索字词。您需要将最终结果构建到您要寻找的结果中。

或者,只需删除Do WhileLoop行,宏就会找到第一项。

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

答案 1 :(得分:0)

在我看来您需要:

查找= Fedora [0-9] {2}:* ^ l

或:

查找= Fedora [0-9] {2}:* [^ l ^ 13]