求助如何用正则表达式获取字符串中两区间内容
内容是这些
Public Function Showit(ByVal tt As string)
msgbox tt
End Function
Public Function Setit(ByVal tt2 As string)
text1.text=tt2
End Function
我想获取到Showit和Setit
自己试了下用这句Function(.*?)ByVal,但获取的内容确实
Function Showit(ByVal
Function Setit(ByVal
万分感谢您的帮助 vb正则
[解决办法]
'此代码由“正则测试工具 v1.1.35”自动生成,请直接调用TestReg过程
Private Sub TestReg()
Dim strData As String
Dim reg As Object
Dim matchs As Object, match As Object
strData = "Public Function Showit(ByVal tt As string)" & vbCrLf & _
"msgbox tt" & vbCrLf & _
"End Function" & vbCrLf & _
"Public Function Setit(ByVal tt2 As string)" & vbCrLf & _
"text1.text=tt2" & vbCrLf & _
"End Function"
Set reg = CreateObject("vbscript.regExp")
reg.Global = True
reg.IgnoreCase = True
reg.MultiLine = True
reg.Pattern = "Function (.*?)\(ByVal"
Set matchs = reg.Execute(strData)
For Each match In matchs
'Debug.Print match.Value
Debug.Print match.SubMatches(0)
Next
End Sub