[算表] 求助如何同時提取不同規則的字符串

作者: 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