我想使用正则表达式查找文本的特殊部分。例如,我有这样的文字:KENNFELD TFSWNWRSA 4 4
我只想从此文本中提取TFSWNWRSA 4 4而不是KENNFELD,然后我想
我写了这段代码,但它返回所有总行:
Dim fso As New FileSystemObject
Dim ts As TextStream
Dim Name As String
Dim regx As New regexp
Dim matchkennfeld As MatchCollection
Dim matchname As MatchCollection
Name = "D:/test_DC.txt"
'Set regexp = CreateObject("vbscript.regexp")
Set ts = fso.OpenTextFile(Name, ForReading)
Do While Not ts.AtEndOfStream
regx.Pattern = "KENNFELD\s+([A-Z 0-9]*)"
Set matchkennfeld = regx.Execute(ts.ReadLine)
If matchkennfeld.Count <> 0 Then
regx.Pattern = "([A-Z 0-9]*)"
' MsgBox matchkennfeld.Item(0)
Set matchname = regx.Execute(matchkennfeld.Item(0))
For Each Match In matchname
MsgBox Match
Next Match
End If
Loop
你能帮我做这份工作吗?