首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Find with通配符查找小括号之间的特定文本

问使用Find with通配符查找小括号之间的特定文本
EN

Stack Overflow用户
提问于 2021-07-29 08:18:46
回答 1查看 69关注 0票数 1

我需要找到特定的文本,比如小括号中的" PL",(),即

案文标准:

  1. 文本“PL”-这两个字母都是首都,并且在“PL”
  2. 文本之前有一个空格应该是粗体的
  3. 文本应该在小括号之间。()

示例案文:

(目标价格:0.22欧元) Bank

  • Jeronimo Martins SGPS SA (JMT,Buy):(目标价格:19.60欧元) 2Q21 Review

  • Ibersol SGPS SA (BCP PL,中性):(目标价:6.50欧元) Cinven获得控制

VBA代码:

代码语言:javascript
复制
    With Selection.Find
        .Text = "\((.*?)\)" ' WhildCard
        .Forward = True
        .Wrap = wdFindStop
        .MatchWildcards = True
        .Execute
    End With
    If Selection.Find.Found Then

    'if found then need to select the paragraph and do something with it.

    End If

如果可以使用Wildcard,请帮助

​

​

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-29 08:27:25

试试下面的代码:

代码语言:javascript
复制
Sub test1()
    With ActiveDocument.Range.Find 'or Selection.Range.Find
        .Text = "\(?*\)"
        .MatchWildcards = True
        Do While .Execute
            If InStr(.Parent.Text, " PL") And .Parent.Font.Bold Then
                'do something with it
                .Parent.Paragraphs(1).Range.Delete
            End If
        Loop
    End With
End Sub

不带括号的Edit2模式

代码语言:javascript
复制
Sub test2()
    Dim rng As Range
    With ActiveDocument.Range.Find
        .Text = " PL"
        .MatchWildcards = True
        Do While .Execute
            If .Parent.Font.Bold Then
                .Parent.Paragraphs(1).Range.Delete
            End If
        Loop
    End With
End Sub
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68572472

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档