求助如何用正则表达式获取字符串中两区间内容

lxl13596 2013-12-01 11:36:44
内容是这些
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
万分感谢您的帮助
...全文
360 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sanweixianshi 2013-12-06
  • 打赏
  • 举报
回复
版主没有将括号考虑在内哦,你试试这个“(?<=Function\s)\w+(?=\(ByVal)”。
lxl13596 2013-12-05
  • 打赏
  • 举报
回复
太感谢两大版主了,谢谢
threenewbee 2013-12-01
  • 打赏
  • 举报
回复
(?<=Function\s)w+?(?=ByVal)
threenewbee 2013-12-01
  • 打赏
  • 举报
回复
(?<=Function\s).*?(?=ByVal)
无·法 2013-12-01
  • 打赏
  • 举报
回复

'此代码由“正则测试工具  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

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧