<script language=vbs>
dim str
str="<div id=cnt>aaa</div>"
set re = new RegExp
re.Pattern ="<\/?div\s*[^>]*>"
re.Global = true
re.test(str)
msgbox re.replace(str,"")
</script>
dim str
str="<div id=cnt>aaa</div>"
set re = new RegExp
re.Pattern ="<\/?div\s*[^>]*>"
re.Global = true
re.test(str)
msgbox re.replace(str,"")
</script>
我得调出来他们来使用的,如果这样用的话只是去掉了匹配的内容,而并不是引用了匹配的内容
请参阅
For Each...Next 语句 | Match 对象 | Matches 集合 |RegExp 对象
要求
版本 5.5
正则表达式子匹配字符串的集合。说明
SubMatches 集合包含了单个的子匹配字符串,只能用 RegExp 对象的 Execute 方法创建。SubMatches 集合的属性是只读的。运行一个正则表达式时,当圆括号中捕捉到子表达式时可以有零个或多个子匹配。SubMatches 集合中的每一项是由正则表达式找到并捕获的的字符串。下面的代码演示了如何从一个正则表达式获得一个 SubMatches 集合以及如何它的专有成员:Function SubMatchTest(inpStr)
Dim oRe, oMatch, oMatches
Set oRe = New RegExp
' 查找一个电子邮件地址(不是一个理想的 RegExp)
oRe.Pattern = "(\w+)@(\w+)\.(\w+)"
' 得到 Matches 集合
Set oMatches = oRe.Execute(inpStr)
' 得到 Matches 集合中的第一项
Set oMatch = oMatches(0)
' 创建结果字符串。
' Match 对象是完整匹配 — [email protected]
retStr = "电子邮件地址是: " & oMatch & vbNewline
' 得到地址的子匹配部分。
retStr = retStr & "电子邮件别名是: " & oMatch.SubMatches(0) ' dragon
retStr = retStr & vbNewline
retStr = retStr & "组织是: " & oMatch. SubMatches(1)' xyzzy
SubMatchTest = retStr
End FunctionMsgBox(SubMatchTest("请写信到 [email protected] 。谢谢!"))