久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      ASP 正則表達式常用的幾種方法(execute、test、replace)

      RegExp就是建立正則的對像。
      如:
      Set regEx = New RegExp

      regEx.Pattern 就是來設(shè)置正則的模式的,
      如:
      regEx.Pattern =”/d+”

      regEx.IgnoreCase = True ‘ 設(shè)置是否區(qū)分大小寫
      regEx.Global = True ‘ 設(shè)置全程可用性。

      RegExp對像有3種方法,分別是execute、test、replace。

      test方法是對指定的字符串執(zhí)行一個正則表達式搜索,并返回一個 Boolean 值指示是否找到匹配的模式。RegExp.Global屬性對Test方法沒有影響。如果找到了匹配的模式,Test方法返回True;否則返回False。
      例子:

      測試的時候,msgbox是vbs的用法,如果是asp文件,需要將msgbox替換為response.write

      復(fù)制代碼 代碼如下:
      Function RegExpTest(patrn, strng)
      Dim regEx, retVal ‘ 建立變量。
      Set regEx = New RegExp ‘ 建立正則表達式。
      regEx.Pattern = patrn ‘ 設(shè)置模式。
      regEx.IgnoreCase = False ‘ 設(shè)置是否區(qū)分大小寫。
      retVal = regEx.Test(strng) ‘ 執(zhí)行搜索測試。
      If retVal Then
      RegExpTest = “找到一個或多個匹配。”
      Else
      RegExpTest = “未找到匹配。”
      End If
      End Function

      MsgBox(RegExpTest(“d+”, “abcd1234”))
      MsgBox(RegExpTest(“d+”, “abcd”))

      Replace 方法替換在正則表達式查找中找到的文本
      例子:
      vbs代碼

      復(fù)制代碼 代碼如下:
      Function ReplaceTest(str,patrn, replStr)
      Dim regEx, str1 ‘ 建立變量。
      ‘str1 = “dog 123.”
      Set regEx = New RegExp ‘ 建立正則表達式。
      regEx.Pattern = patrn ‘ 設(shè)置模式。
      regEx.IgnoreCase = True ‘ 設(shè)置是否區(qū)分大小寫。
      ReplaceTest = regEx.Replace(str, replStr) ‘ 作替換。
      End Function

      MsgBox(ReplaceTest(“dog 123″,”d+”, “cat”)) ‘將字符串中的123替換為cat

      Execute 方法,則是對指定的字符串執(zhí)行正則表達式搜索。這里又涉及到Match對像和Matches 集合。Matches 集合就是match的對像集合。Matches 集合中包含若干獨立的 Match 對象,只能使用 RegExp 對象的 Execute 方法來創(chuàng)建之。例子:
      vbs測試代碼

      復(fù)制代碼 代碼如下:
      Function RegExpTest(patrn, strng)
      Dim regEx, Match, Matches ‘ 建立變量。
      Set regEx = New RegExp ‘ 建立正則表達式。
      regEx.Pattern = patrn ‘ 設(shè)置模式。
      regEx.IgnoreCase = True ‘ 設(shè)置是否區(qū)分大小寫。
      regEx.Global = True ‘ 設(shè)置全程可用性。
      Set Matches = regEx.Execute(strng) ‘ 執(zhí)行搜索。
      For Each Match in Matches ‘ 遍歷 Matches 集合。
      RetStr = RetStr & Match.FirstIndex & “。匹配的長度為”&” ”
      RetStr = RetStr & Match.Length &” ”
      RetStr = RetStr & Matches(0) &” ” ‘值為123
      RetStr = RetStr & Matches(1)&” ” ‘值為44
      RetStr = RetStr & Match.value&” ” ‘值為123和44的數(shù)組
      RetStr = RetStr & vbCRLF
      Next
      RegExpTest = RetStr
      End Function
      MsgBox(RegExpTest(“d+”, “123a44”))
      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號