|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Mr_Ying 发表于 2015-3-18 19:28
现在C列返回值有以下这三种情况,二三情况目前正则都包括了,一图这种情况能否整合进去呢?
1图有结束标 ... - Sub test()
- Open ThisWorkbook.Path & "\合并源结果.txt" For Input As #1
- ar = Split(StrConv(InputB(LOF(1), #1), vbUnicode), "索引页面")
- Close #1
- ReDim br(1 To UBound(ar), 1 To 3)
- Set regx = CreateObject("vbscript.regexp")
- regx.Pattern = "(?:下一篇|^\s*)(?:(?!发信人)[\s\S])+发信人:\s*([^(\s]+)\s*[\s\S]+?\(([\w\s]+\d+:\d+:\d+\s\d+)|\r\n--[\s\S]+FROM:\s*(\d+(?:\.[\d*]+){3})\]\s*$"
- regx.Global = True
- For Each k In ar
- Set mh = regx.Execute(k)
- If mh.Count <> 0 Then
- n = n + 1
- br(n, 1) = mh(0).submatches(0)
- br(n, 2) = mh(0).submatches(1)
- If mh.Count >= 2 Then _
- br(n, 3) = mh(1).submatches(2)
- End If
- Next
- Range("a1").Resize(UBound(br), 3) = br
- End Sub
复制代码 |
|