|
本帖最后由 tcmsod 于 2017-5-28 17:57 编辑
原po.txt中相关字段如下: 1 GZ140301_0 0464052A A 42.00 ea 3.4910 USD 146.62 25-May-17 Replace CIF AIR
准备提取GZ140301_0 0464052A A 42.00 ea 3.4910 USD 146.62 25-May-17,但下面的代码来提取出来的却是整行,求助高手如何写正则表达式,谢谢。
Sub potest()
Set regex = CreateObject("vbscript.regexp")
regex.Pattern = "GZ\d{6,}.+\d{2}\-\w{3}\-\d{2}"
Open ThisWorkbook.Path & "\po.txt" For Input As #1
Open ThisWorkbook.Path & "\output.txt" For Output As #2
Do While Not EOF(1)
Line Input #1, s
If regex.test(s) Then
Print #2, s
End If
Loop
Close #1, #2
Set regex = Nothing
End Sub
Sub potest()
Set regex = CreateObject("vbscript.regexp")
regex.Pattern = "GZ\d{6,}.+\d{2}\-\w{3}\-\d{2}"
Open ThisWorkbook.Path & "\po.txt" For Input As #1
Open ThisWorkbook.Path & "\output.txt" For Output As #2
Do While Not EOF(1)
Line Input #1, s
If regex.test(s) Then
Print #2, regex.Execute(s)(0)
End If
Loop
Close #1, #2
Set regex = Nothing
End Sub
|
|