4,008
社区成员
发帖
与我相关
我的任务
分享
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分字符大小写。
regEx.Global = True ' 设置全局可用性。
Set Matches = regEx.Execute(strng) ' 执行搜索。
For Each Match in Matches ' 遍历匹配集合。
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function
MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))
function RegExpTest(patrn, strng) {
var rx = new RegExp(patrn, 'ig'), RetStr = '';
while (m = rx.exec(strng)) RetStr += "Match found at position " + m.index + ". Match Value is '" + m + "'.\n"
return RetStr;
}
alert(RegExpTest("is.", "IS1 is2 IS3 is4"))