比较随意的一些ASP正则表达式方面的笔记(或学习小甜品) =====================================

<%' 方法说明:Set RsObj = Server.CreateObject快捷Function [&rg](ByRef rgRef, ByVal pe, ByVal ig, ByVal gb, ByVal [?Casually]) Call RgNew(rgRef, pe, ig, gb,[]) End Function 

' 清空正则表达式对象Function [!rg](ByRef rgRef) Set rgRef = Nothing End Function 

' 测试是否符合正则表达式Function InRg(ByRef rgRef, ByVal str)     InRg = rgRef.Test(CStr(str)) End Function 

' 获取正则表达式匹配的个数Function RgNum(ByRef rgRef, ByVal str)     RgNum = Clng("0"&rgRef.Execute(str).Count) End Function 

' 创建或重新初始化一个正则表达式Function RgNew(ByRef rgRef, ByVal pe, ByVal ig, ByVal gb, ByVal [?Casually]) If Not IsObject(rgRef) Then Set rgRef = New RegExp ElseIf rgRef is Nothing Then Set rgRef = New RegExp End If If Not IsEll(pe) Then         rgRef.Pattern = peEnd If 

If Not IsEll(ig) Then         rgRef.IgnoreCase = Bool(ig)End If 

If Not IsEll(gb) Then         rgRef.Global = Bool(gb)End If End Function 

' 判断是否"有"还是"没有"' 判断是否"是"还是"不是"' 判断是否"存在"还是"不存在"' 判断是否"有用"还是"没用"' .........等等Function Bool(ByVal val) If isEll(val) Then         Bool = False ElseIf TypeName(val) = "Interger" And Int(val) = 0 Then         Bool = False ElseIf TypeName(val) = "String" Then Select Case LCase(Cstr(val)) Case "","0","false"             Bool = False End Select ElseIf TypeName(val) = "Boolean" Then         Bool = CBool(val) Else         Bool = True End If End Function 

' 省略或缺少了Function IsEll(ByVal val)     IsEll = CBool(isNull(val) Or isEmpty(val) Or TypeName(val)="Error") End Function :Function IsLack(ByVal val)     IsLack = IsEll(val)End Function 

' 正则表达式调试' 举例: dim r : [&rg] r,"\bdreamyoung(\d{0,4})_([^dreamyoung]+)\b", , ,[]  debugReg r,"dreamyoung2011_sw.hf,dreamyoung2012_sw.hf and dreamyoung2013_sw.hf$",,[] Function debugReg(ByRef rgRef, ByVal str, ByVal endFlag, ByVal [?Casually])     [<<ln] "<div style=""font-weight:bold; margin:10px; padding:10px; border-color:#036; border-style:dashed; border-width:thick;"">"     [<<ln] "regExp.<b><font color=red>Pattern</font></b> = " & rgRef.Pattern     [<<ln] "regExp.<b><font color=green>IgnoreCase</font></b> = " & rgRef.IgnoreCase & "&nbsp;&nbsp;&nbsp;<font color=#CCCCCC>(False For Default)</font>"     [<<ln] "regExp.<b><font color=blue>Global</font></b> = " & rgRef.Global & "&nbsp;&nbsp;&nbsp;<font color=#CCCCCC>(False For Default)</font>"     [<<ln] "<font color=#000000>Matches Is A Dictionary For Match Object</font>" & _ "&nbsp;&nbsp;<font color=#CCCCCC>Matches Come From : Set Matches = RegExp.Execute(str)</font>"     [<<ln] "<font color=#000000>Matche Come From : Set Matche = Matches.Item(i)</font>"     [<<ln] "<font color=#000000>SubMatches Is A Dictionary For String</font>" &_ "&nbsp;&nbsp;<font color=#CCCCCC>SubMatches Come From : Set SubMatches = Match.SubMatches</font>"     [<<ln] "<font color=#000000>SubMatche(String) Come From : SubMatch = SubMatches.Item(i)&nbsp;&nbsp;&nbsp;<font color=#CCCCCC>(Tip:No ""Set"" , Because It is only a string!)</font></font>" '[<<!] TypeName(str) If Not IsEll(str) Then         [<<] "---------------------------------------------------"         [<<ln] "---------------------------------------------------"         [<<ln] "Input String: " & Server.HTMLEncode(str)         [<<ln] "regExp.Test("""&str&""") = " & rgRef.Test(str) ' Matches集合(包含0或多个Match对象) Dim mes : Set mes = rgRef.Execute(str) Dim rgCount : rgCount = mes.Count         [<<ln] "regExp.Execute("""&str&""").Counts = "& rgCount If rgCount > 0 Then ' Match对象(含各种属性) Dim m0 : Set m0 = mes(0)             [<<ln] "regExp.Execute("""&str&""").Item(0) = " & m0             [<<ln] "regExp.Execute("""&str&""").Item(0).FirstIndex = " & m0.FirstIndex             [<<ln] "regExp.Execute("""&str&""").Item(0).Length = " & m0.Length             [<<ln] "regExp.Execute("""&str&""").Item(0).Value = " & m0.Value 

' SubMatches集合(包含0或多个字符串) Dim submes : Set submes = m0.SubMatches Dim smCount : smCount = submes.Count             [<<ln] "regExp.Execute("""&str&""")(0).SubMatches.Counts = "& smCount If smCount > 0 Then Dim sm0 : sm0 = submes(0)                 [<<ln] "regExp.Execute("""&str&""")(0).SubMatches.Item(0) = " & sm0 & Space(10) & "<font color=#CCCCCC>This is the 1st sub match, For More:</font>" Dim i For Each subStr In submes                     [<<ln] "regExp.Execute("""&str&""")(0).SubMatches.Item("&(i-0)&") = " & subStr                     i = i + 1 Next End If End If End If     [<<ln] "</div>" 

If Bool(endFlag) Then         [<<!] []End If End Function %>

测试的输出结果为:


regExp.Pattern = \bdreamyoung(\d{0,4})_([^dreamyoung]+)\b
regExp.IgnoreCase = False   (False For Default)
regExp.Global = False   (False For Default)
Matches Is A Dictionary For Match Object  Matches Come From : Set Matches = RegExp.Execute(str)
Matche Come From : Set Matche = Matches.Item(i)
SubMatches Is A Dictionary For String  SubMatches Come From : Set SubMatches = Match.SubMatches
SubMatche(String) Come From : SubMatch = SubMatches.Item(i)   (Tip:No "Set" , Because It is only a string!)
------------------------------------------------------------------------------------------------------
Input String: dreamyoung2011_sw.hf,dreamyoung2012_sw.hf and dreamyoung2013_sw.hf$
regExp.Test("dreamyoung2011_sw.hf,dreamyoung2012_sw.hf and dreamyoung2013_sw.hf$") = True
regExp.Execute("dreamyoung2011_sw.hf,dreamyoung2012_sw.hf and dreamyoung2013_sw.hf$").Counts = 1
regExp.Execute("dreamyoung2011_sw.hf,dreamyoung2012_sw.hf and dreamyoung2013_sw.hf$").Item(0) = dreamyoung2011_sw.hf,
regExp.Execute("dreamyoung2011_sw.hf,dreamyoung2012_sw.hf and dreamyoung2013_sw.hf$").Item(0).FirstIndex = 0
regExp.Execute("dreamyoung2011_sw.hf,dreamyoung2012_sw.hf and dreamyoung2013_sw.hf$").Item(0).Length = 21
regExp.Execute("dreamyoung2011_sw.hf,dreamyoung2012_sw.hf and dreamyoung2013_sw.hf$").Item(0).Value = dreamyoung2011_sw.hf,
regExp.Execute("dreamyoung2011_sw.hf,dreamyoung2012_sw.hf and dreamyoung2013_sw.hf$")(0).SubMatches.Counts = 2
regExp.Execute("dreamyoung2011_sw.hf,dreamyoung2012_sw.hf and dreamyoung2013_sw.hf$")(0).SubMatches.Item(0) = 2011 This is the 1st sub match, For More:
regExp.Execute("dreamyoung2011_sw.hf,dreamyoung2012_sw.hf and dreamyoung2013_sw.hf$")(0).SubMatches.Item(0) = 2011
regExp.Execute("dreamyoung2011_sw.hf,dreamyoung2012_sw.hf and dreamyoung2013_sw.hf$")(0).SubMatches.Item(1) = sw.hf,

转载于:https://www.cnblogs.com/dreamyoung/archive/2012/04/07/2436334.html

ASP正则表达式方面小笔记相关推荐

  1. 【课程设计】UWP 开发入门小笔记(1)

    UWP 开发入门小笔记(1) 零.介绍 一.系列介绍[p1] 二.创建第一个属于自己的UWP应用[p2] (一)一个button的属性: (二)修改属性的三种方法 (三)字号(以后会细讲) 三.UWP ...

  2. .NET小笔记之程序集

    前面文章小笔记之--.NET Framework的内容 讲到了c#开发的程序在VS中可以编译成MSIL代码,那么这些代码保存在什么地方呢?答案就是程序集中.那么程序集又是以什么形式的文件存储呢?程序集 ...

  3. ASP生成HTML讲座笔记

    2005-7-9 ASP生成HTML讲座笔记 题目:ASP自动生成HTML文件 首先这项技术的优点是:(1)减轻数据库的压力;(2)把数据库和页面隔离开来 然后给大家讲一下实现原理.. ASP生成HT ...

  4. 一个PHP使用重新整理数组的小笔记

    一个PHP使用重新整理数组的小笔记 今天写PHP的时候,因为写好的一个库接受的一个数组参数中,第一个元素不符合那个函数的要求,所以要unset掉.于是我unset(0);但是这个操作之后发现数组中的0 ...

  5. linux数据包注释,关于 linux中TCP数据包(SKB)序列号的小笔记

    关于  SKB序列号的小笔记 为了修改TCP协议,现在遇到了要改动tcp分组的序列号,但是只是在tcp_sendmsg函数中找到了SKB的end_seq  一直没有找到seq 不清楚在那里初始化了,就 ...

  6. 【iOS开发每日小笔记(一)】UIPickerView 自动选择某个component的某个row

    这篇文章是我的[iOS开发每日小笔记]系列中的一片,记录的是今天在开发工作中遇到的,可以用很短的文章或很小的demo演示解释出来的小心得小技巧.它们可能会给用户体验.代码效率得到一些提升,或是之前自己 ...

  7. 【iOS开发每日小笔记(二)】gitHub上的开源“瀑布流”使用心得

    这篇文章是我的[iOS开发每日小笔记]系列中的一片,记录的是今天在开发工作中遇到的,可以用很短的文章或很小的demo演示解释出来的小心得小技巧.它们可能会给用户体验.代码效率得到一些提升,或是之前自己 ...

  8. ASP.Net2.0小技巧 保持滚动条的位置 焦点移动到某个控件 $符号轻松的使用FindControl...

    您可能不知道的ASP.Net2.0小技巧 <!-- 页码和简介 --> 1.  在提交页面之后,保持滚动条的位置 可以在page指令上加上MaintainScrollPositionOnP ...

  9. Python小笔记——urllib2得到重定向最终链接

    Python小笔记--urllib2得到重定向最终链接 强大的urllib2其实是有处理链接重定向的功能的,但是如何得到跳转最终的链接呢?其实相当简单,做个小笔记,也防止自己忘记了. 接下来用http ...

最新文章

  1. 用C语言实现控制台模拟显示时
  2. 超图桌面版使用模板创建数据源
  3. Cisco 3750文件系统学习总结
  4. Logistic混沌序列加密
  5. FCC新主席发推特称赞亚马逊,但被质疑违反了联邦道德准则
  6. 一表理清如何正确选择可视化图表,掌握后再也不怕用错图表
  7. linux之chattr命令
  8. java窗口小程序atm_简单的小程序实现ATM机操作
  9. 2013年1月第1个周末
  10. 轻松学习理解ACL访问控制列表(转)
  11. 北斗导航 | 基于最小二乘残差法与奇偶矢量法的RAIM算法(附代码)
  12. Word文件标尺工具不见了,怎么恢复
  13. 如何在java中实现小数点自增_java保留小数的四种实现方法
  14. IGBT的双脉冲测试实验
  15. 【题解】CF#855 G-Harry Vs Voldemort
  16. python爬虫笔记(3)
  17. 项目质量管理工具--鱼骨图(石川图)
  18. 电商数据库详细设计说明书
  19. python实现百万英雄答题神器
  20. 小米mix2s android8,小米MIX2S谷歌Pixel安卓刷机包(完整系统固件升级包安卓8.1)

热门文章

  1. romfs, cramfs和ramdisk
  2. 奔跑吧Linux内核初识
  3. [react-router] React-Router的实现原理是什么?
  4. [react] react中你用过哪些第三方的中间件
  5. [html] 你知道什么是反向链接吗?它有什么应用场景呢?
  6. 工作399-openType=“getUserInfo“ lang=“zh_CN“ bindgetuserinfo=“getUserInfo“
  7. [html] HTML与XHTML二者有不同
  8. [css] 说说浏览器解析CSS选择器的过程?
  9. 前端学习(2750):global全局外观设置
  10. 工作总结20:遮挡层