asp 正则表达式
2009-04-03 21:47
267 查看
asp 的正则表达式资料 网上很多,但是很多讲的不完整,从一个E文的文章上看到了个究竟,下面举例说明如何使用
a = "1,2,3,7_UP,sss"
Set myRegExp = New RegExp
myRegExp.Pattern = "(.*)(\d)_UP(.*)"
set matchs = myRegExp.execute(a)
response.Write(matchs(0).SubMatches.count &"<br>")
response.write(matchs(0).SubMatches(0) & "<br>")
response.write(matchs(0).SubMatches(1) & "<br>")
response.write(matchs(0).SubMatches(2) & "<br>")
'结果是:
'3
'1,2,3,
'7
',sss
原文是这样说滴:“
The MatchCollection object returned by the RegExp.Execute method is a collection of Match objects. It has only two read-only properties. The Count property indicates how many matches the collection holds. The Item property takes an index parameter (ranging from zero to Count-1), and returns a Match object. The Item property is the default member, so you can write MatchCollection(7) as a shorthand to MatchCollection.Item(7).
The easiest way to process all matches in the collection is to use a For Each construct, e.g.:
The Match object has four read-only properties. The FirstIndex property indicates the number of characters in the string to the left of the match. If the match was found at the very start of the string, FirstIndex will be zero. If the match starts at the second character in the string, FirstIndex will be one, etc. Note that this is different from the VBScript Mid function, which extracts the first character of the string if you set the start parameter to one. The Length property of the Match object indicates the number of characters in the match. The Value property returns the text that was matched.
The SubMatches property of the Match object is a collection of strings. It will only hold values if your regular expression has capturing groups. The collection will hold one string for each capturing group. The Count property indicates the number of string in the collection. The Item property takes an index parameter, and returns the text matched by the capturing group. The Item property is the default member, so you can write SubMatches(7) as a shorthand to SubMatches.Item(7). Unfortunately, VBScript does not offer a way to retrieve the match position and length of capturing groups.
”
地址是:http://www.regular-expressions.info/vbscript.html
a = "1,2,3,7_UP,sss"
Set myRegExp = New RegExp
myRegExp.Pattern = "(.*)(\d)_UP(.*)"
set matchs = myRegExp.execute(a)
response.Write(matchs(0).SubMatches.count &"<br>")
response.write(matchs(0).SubMatches(0) & "<br>")
response.write(matchs(0).SubMatches(1) & "<br>")
response.write(matchs(0).SubMatches(2) & "<br>")
'结果是:
'3
'1,2,3,
'7
',sss
原文是这样说滴:“
The MatchCollection object returned by the RegExp.Execute method is a collection of Match objects. It has only two read-only properties. The Count property indicates how many matches the collection holds. The Item property takes an index parameter (ranging from zero to Count-1), and returns a Match object. The Item property is the default member, so you can write MatchCollection(7) as a shorthand to MatchCollection.Item(7).
The easiest way to process all matches in the collection is to use a For Each construct, e.g.:
' Pop up a message box for each match Set myMatches = myRegExp.Execute(subjectString) For Each myMatch in myMatches msgbox myMatch.Value, 0, "Found Match" Next
The Match object has four read-only properties. The FirstIndex property indicates the number of characters in the string to the left of the match. If the match was found at the very start of the string, FirstIndex will be zero. If the match starts at the second character in the string, FirstIndex will be one, etc. Note that this is different from the VBScript Mid function, which extracts the first character of the string if you set the start parameter to one. The Length property of the Match object indicates the number of characters in the match. The Value property returns the text that was matched.
The SubMatches property of the Match object is a collection of strings. It will only hold values if your regular expression has capturing groups. The collection will hold one string for each capturing group. The Count property indicates the number of string in the collection. The Item property takes an index parameter, and returns the text matched by the capturing group. The Item property is the default member, so you can write SubMatches(7) as a shorthand to SubMatches.Item(7). Unfortunately, VBScript does not offer a way to retrieve the match position and length of capturing groups.
”
地址是:http://www.regular-expressions.info/vbscript.html
相关文章推荐
- ASP.NET中的17种正则表达式
- asp.net开发时经常用到的一些正则表达式
- ASP.NET 中的正则表达式
- ASP.NET 中的正则表达式
- 通过几个非常实用的例子了解asp中使用正则表达式
- 正则表达式在UBB论坛中的应用(http://www.blueidea.com/bbs/newsdetail.asp?id=303249)
- ASP.NET MVC Model 验证 常用正则表达式
- ASP.NET 中的正则表达式
- asp.net 验证正则表达式
- asp.net mvc Model验证总结及常用正则表达式
- 在ASP.NET WEB 应用程序中连接SQL2000 为什么报 SQL20005 40 错误的解决方法.
- [ASP.NET]在ASP.NET中使用AJAX的简单方法
- 在 ASP.NET MVC 项目中使用 WebForm
- ASP.NET中的AJAX应用开发总结
- 超长文章(HTML格式)自动分页,用ASP和JS实现
- ASP得到域中用戶信息
- 温故知新ASP.NET 2.0(C#)(5) - Localization(本地化,多语言)
- Asp.Net中基于Forms验证的角色验证授权--转
- :asp.net实现分组全选部分复选框
- ASP.NET 2.0中轻松实现网站换肤(转)