日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ASP正则表达式方面小笔记

發布時間:2023/12/10 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ASP正则表达式方面小笔记 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

比較隨意的一些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 = pe
End 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正则表达式方面小笔记的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。