首页 > 解决方案 > 将字符串的一部分从一组字符删除到另一个字符

问题描述

我有一个 Excel 工作表,我想删除一些 HTML 标记。我的问题是一些标签不仅仅是简单的<div>标签,而是有额外的字符,比如<div class="ExternalClassEA74AB3F178E48EDAD3BDE4FC90B1182">替换,<div直到我们到达>标签的结尾。如何用“”替换这样的字符串部分。谢谢。

标签: excelvba

解决方案


Sub RemoveDivs()
    Dim html$
    html = "Some other text<div class=""ExternalClassEA74AB3F178E48EDAD3BDE4FC90B1182""> and here too"
    With CreateObject("VBScript.RegExp")
        .Pattern = "<div.*?>": .Global = True
        html = .Replace(html, "")
    End With
    MsgBox html
End Sub

推荐阅读