- Option Explicit
-
- Test
-
- '************************************************************************
- Sub Test()
- '************************************************************************
-
- Dim str, strPattern
- str = "https://agc.qq.com/show/chan"
- strPattern = "http[s]{0,1}:\/\/[0-9A-z\.]+?\/([^\/]+)?[\/]{0,1}?.*"
- MsgBox GetRE_SM0(str, strPattern)
-
- End Sub
-
- '************************************************************************
- '正則表達式:取得字符串的第一個子匹配項目
- '************************************************************************
- Function GetRE_SM0(ByVal str, ByVal strPattern)
- Dim oRE
- Set oRE = CreateObject("vbScript.regExp")
- oRE.Pattern = strPattern
- If oRE.Test(str) Then
- If oRE.Execute(str)(0).SubMatches.Count >= 1 Then
- GetRE_SM0 = oRE.Execute(str)(0).SubMatches(0)
- End If
- End If
- Set oRE = Nothing
- End Function
复制代码
|