[算表] 求助如何同时提取不同规则的字符串

楼主: yyingx (bless)   2015-03-10 22:51:09
软件:MS Office
版本:2007
如图所示 http://ppt.cc/F-tr
文件下载位置 http://ppt.cc/7n-v
我要提取红框的字符串
他们的正则表达式分别是
水木社区自动发信系统 \(([^\)]+)\)
发信人: ([A-Za-z]\w+)
\[竞猜结果\](.*)
请问如何一次性提取这些字符串呢
类似这样的代码
Sub 提取() '按照txt顺序提取,无排序
Dim ar(1 To 20000, 1 To 2), br, rep, i, n, m, str, max
Dim fn$
Set rep = CreateObject("vbscript.regexp")
fn = Dir("C:\Users\shawn\Desktop\提取汇总150305yyingx\合并源数据\合并源结果.
txt")
rep.Global = True
rep.Pattern = "([A-Za-z]\w+)[0-9 .]+([/+-]\d+)"
Open "C:\Users\shawn\Desktop\提取汇总150305yyingx\合并源数据\" & fn For
Input As #1
str = StrConv(InputB(LOF(1), 1), vbUnicode)
Close #1
Sheet3.[A:B] = ""
For Each m In rep.Execute(str)
n = n + 1
ar(n, 1) = Application.Clean(m.submatches(0))
ar(n, 2) = m.submatches(1)
max = Application.max(max, Len(ar(n, 1) & ar(n, 2)))
Next
Sheet3.[A1] = "ID"
Sheet3.[B1] = "盈利"
Sheet3.[A2].Resize(n, 2) = ar
Call fzpx
End Sub

Links booklink

Contact Us: admin [ a t ] ucptt.com