【问题标题】:Match shortest option匹配最短选项
【发布时间】:2017-02-06 22:14:32
【问题描述】:

我正在尝试使用 Outlook 2013 VBA 通过拉出并替换 部分来修改电子邮件正文。但是,对于多个跨度,我无法强制正则表达式只选择一个跨度。

基于其他一些搜索,我正在尝试使用否定前瞻,但失败了。

下面的结果是:<span><span style = blah blah>Tags: test, test2</span>

想要的结果是:<span style = blah blah>Tags: test, test2</span>

测试模块代码:

Sub regextest()
Dim regex As New RegExp
Dim testStr As String

testStr = "a<span><span style=blah blah>Tags: test, test2</span></span>"

regex.pattern = "<span.*?(?:(span)).*?Tags:.*?</span>"

Set matches = regex.Execute(testStr)

For Each x In matches
    Debug.Print x 'Result: <span><span style = blah blah>Tags: test, test2</span>
Next
End Sub

谢谢!

【问题讨论】:

标签: regex vba outlook regex-lookarounds negative-lookbehind


【解决方案1】:

Wiktor 在上述 cmets 中的回答符合我的目的:

&lt;span\b[^&lt;]*&gt;[^&lt;]*Tags:[^&lt;]*&lt;/span&gt;

只要在两个跨度端之间没有“

感谢维克托!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多