在asp中使用regex删除样式属性

时间:2012-02-17 09:58:35

标签: regex string asp-classic vbscript

如何在asp中使用正则表达式从任何标签中删除样式属性?

from:

<div style="margin-top:10px;">test</div>

to:

<div>test</div>



Set objRegExp = New regexp
objRegExp.Pattern = "/style\s*=\s*(\'|').+(\'|')/i"
objRegExp.IgnoreCase = True
objRegExp.Global = True
Set resp = objRegExp.Execute(strWordHTML)
For Each respItem In resp
    strWordHTML= replace(strWordHTML,respItem.Value,"")
Next
Set resp = Nothing
Set objRegExp = Nothing

解决了 *

(\sstyle=['""][^'""]+?['""])

2 个答案:

答案 0 :(得分:2)

不使用正则表达式而未经过测试但是这样的事情应该可行

str = "<div style=""margin-top:10px;"">test</div>"
start = InStr(str, "style")
first = InStr(start, str, """")
second = InStr(first, str, """")

result = Mid(str, 1, start - 1) + Mid(str, second + 1)

答案 1 :(得分:-1)

 dim result = Regex.Replace(HtmlText, "style[^>]*", "")