正则用不了submatches

晃仙 2019-06-28 07:27:55
Sub demo() '想使用正则表达式进行数据处理,但是调试的时候到正则submatches时候说对象不适用该属性或方法,这是为什么呢? 给了s和用正则编辑器的结果,正则表达式应该对的 Worksheets("Sheet2").Activate Dim s As String, myreg As Object, reg1 As Object, myreg1 As Object, i As Integer i = 2 s = Worksheets("Sheet3").Cells(1, 1) Set myreg = CreateObject("VBscript.regexp") With myreg .Global = True .Pattern = "预订\|.*?\|(.*?)\|(?:.*?\|){4}(.*?)\|(.*?)\|(.*?)\|(?:.*?\|){19}(.*?)\|(.*?)\|(.*?)\|" End With Set reg1 = myreg.Execute(s) For Each myreg1 In reg1 Cells(i, 1) = reg1.submatches(0) Cells(i, 2) = reg1.submatches(1) Cells(i, 3) = reg1.submatches(2) Cells(i, 4) = reg1.submatches(3) Cells(i, 7) = reg1.submatches(4) Cells(i, 6) = reg1.submatches(5) Cells(i, 5) = reg1.submatches(6) i = i + 1 Next myreg1
...全文
181 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
晃仙 2019-06-29
  • 打赏
  • 举报
回复
老师老师,是我写错了,我写成了reg1.应该是myreg1
milaoshu1020 2019-06-28
  • 打赏
  • 举报
回复
第几个reg1.submatches(?)出的错?

2,462

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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