【发布时间】:2018-09-14 19:15:31
【问题描述】:
我有这个 xml:
<doc>
<ContactPrimaryEmail></ContactPrimaryEmail>
<ContactAlternateEmail></ContactAlternateEmail>
<ContactPrimaryMobile>+00xxxxxx</ContactPrimaryMobile>
<ContactAlternateMobile></ContactAlternateMobile>
</doc>
我想在 VBScript 中应用正则表达式来替换 ContactPrimaryMobile 属性的 content "+00xxxxxx" strong>,只需更改数字即可:
<ContactPrimaryMobile>+00xxxxxx</ContactPrimaryMobile>
我是 vbscripting 的新手,我在创建对象和应用模式方面的技能有限,所以请你帮我转换这个正则表达式以在 VBScript 中使用它:
(?<=\<ContactPrimaryMobile\>)(.*)(?=\<\/ContactPrimaryMobile)
更新 我明白了:
对象不支持此属性或方法:'Submatches'
执行时:
Dim oRE, oMatches
Set oRE = New RegExp
oRE.Pattern = "<ContactPrimaryMobile>(.*?)</ContactPrimaryMobile>"
oRE.Global = True
Set oMatches = oRE.Execute("<doc><ContactPrimaryEmail></ContactPrimaryEmail><ContactAlternateEmail></ContactAlternateEmail><ContactPrimaryMobile>+00xxxxxx</ContactPrimaryMobile><ContactAlternateMobile></ContactAlternateMobile></doc>")
Wscript.Echo oMatches.Submatches(0)
【问题讨论】:
-
使用
<ContactPrimaryMobile>(.*?)</ContactPrimaryMobile>并获取match.Submatches(0)值。如果您需要更具体的帮助,请显示您的代码。 -
我得到这个对象不支持这个属性或方法:'Submatches' 执行时:Dim oRE, oMatches Set oRE = New RegExp oRE.Pattern = "
(.*?)" oRE.Global = True Set oMatches = oRE.Execute(" ") Wscript.Echo oMatches.Submatches(0) 还有什么帮助吗?+00xxxxxx -
请将其添加到问题正文中。您为什么要在匹配集合上获取子匹配?访问第一项。
Wscript.Echo oMatches(0).Submatches(0) -
非常感谢您的回复!
-
不只是一个,但我真正需要的是用一个新的替换xml中的数字。
标签: regex vbscript asp-classic