当前位置: 首页 > 图文教程 > 脚本技术 > VBScript > VBS教程:对象-Matches 集合

VBScript
VBS教程:VBscript语句-Execute 语句
VBS教程:VBscript语句-Erase 语句
VBS教程:VBscript语句-Do...Loop 语句
VBS教程:VBscript语句-Dim 语句
VBS教程:VBscript语句-Const 语句
VBS教程:VBscript语句-Class 语句
VBS教程:VBscript语句-Call 语句
VBS教程:VBscript语句-功能介绍
VBS教程:VBscript属性-Value 属性
VBS教程:VBscript属性-Source 属性
VBS教程:VBscript属性-Pattern 属性
VBS教程:VBscript属性-Number 属性
VBS教程:VBscript属性-Length 属性
VBS教程:VBscript属性-IgnoreCase 属性
VBS教程:VBscript属性-HelpFile 属性
VBS教程:VBscript属性-HelpContext 属性
VBS教程:VBscript属性-Global 属性
VBS教程:VBscript属性-FirstIndex 属性
VBS教程:VBscript属性-Description 属性
VBS教程:VBscript属性-功能介绍

VBScript 中的 VBS教程:对象-Matches 集合


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-11   浏览: 53 ::
收藏到网摘: n/a

Matches 集合

正则表达式 Match 对象的集合。

说明

Matches 集合中包含若干独立的 Match 对象,只能使用 RegExp 对象的 Execute 方法来创建之。与独立的 Match 对象属性相同,Matches `集合的一个属性是只读的。

在执行正则表达式时,可能产生零个或多个 Match 对象。每个 Match 对象都提供了与正则表达式匹配的字符串的访问入口、字符串的长度,以及标识匹配位置的索引。

下面的代码将说明如何使用正则表达式查找获得 Matches 集合,以及如何循环遍历集合:

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 ' 循环遍历Matches集合。 RetStr = RetStr & "Match found at position " RetStr = RetStr & Match.FirstIndex & ". Match Value is '" RetStr = RetStr & Match.Value & "'." & vbCRLF Next RegExpTest = RetStrEnd FunctionMsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))