正規表現を使用して、テキストの特定の部分を見つけたいです。たとえば、次のようなテキストがあります: 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
この仕事を手伝ってくれませんか?