【问题标题】:ASP wildcard substring replace/removeASP 通配符子字符串替换/删除
【发布时间】:2014-02-24 04:09:08
【问题描述】:

早上,

我有一个包含大量 HTML 和其他项目的 ASP 变量。

dim mvariable : mvariable = "<div id=""constantID"">Some random text</div>"

我的问题是我需要替换 &lt;div&gt; 中的文本(使用 ASP,而不是客户端)。 &lt;div&gt; 的内容可以是任何内容,但其 ID attr 始终相同。

我该怎么做?

Jez D

【问题讨论】:

    标签: string asp-classic replace str-replace


    【解决方案1】:

    如果变量不包含嵌套的 html 元素,您可以使用 Regex 来完成。否则,您必须使用 html 解析器,因为 Regex 不是解析器,不应用于此类目的。

    dim mvariable : mvariable = "<div id=""constantID"">Some random text</div>"
    
    Dim ReDiv
    Set ReDiv = New RegExp
        ReDiv.IgnoreCase = True
        ReDiv.Pattern = "(<div id=""constantID"">)[\s\S]*?(</div>)"
    
    Response.Write ReDiv.Replace(mvariable, "$1newContent$2")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-21
      • 2012-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      • 2016-06-12
      相关资源
      最近更新 更多