我有一个文本(如果需要,已存储在String变量中)。 该文本的结构如下:
(124314)GSK67SJ / 11 ADS SDK
等等等等等等等等等等 blah blah blah blah blah blah(298)2KEER / 98 EOR PRT
blah blah blah 等等等等等等等等等等等
对于他们每个人,我必须存储号码,前3个字母,第2个3个字母,以及"等等等等。在Excel文件的4列中。 让我们说列是A,B,C,D。结果应该如下(来自A1):
124314 | ADS | SDK |等等等等等等。
298 | EOR | PRT |等等......
.........
非常感谢任何帮助
答案 0 :(得分:0)
我设法解决了它
Dim RegX As VBScript_RegExp_55.RegExp 'Rememeber to reference it...
Dim Mats As Object
Dim TextFiltered As String
Dim counter As Integer
Set RegX = New VBScript_RegExp_55.RegExp
With RegX
.Global = True
.MultiLine = True
.Pattern = "[\s]{2,}(?!\(\s+(\d+)\s+\))" 'This will clear the annoying splitting into different lines of the "blah blah" A PART for the ones before "( number )"
TextFiltered = .Replace(TextFiltered, " ") ' You could also write [\r\n] instead of [\s] but in that way you eliminate all the spaces in one hit
End With
With RegX 'This is the pattern you're looking for, the brackets mean different elements you could retrieve from the array of the results
.Pattern = "\(\s+(\d+)\s+\)(\s+\w+/[0-9]{2}\s+)([A-Z]{3})\s+([A-Z]{3})\s+(.+)" 'I think you can remove the "+" from the "\s"
Set Mats = .Execute(TextFiltered)
End With
For counter = 0 To Mats.Count - 1 'SubMatches is what will give you the various elements one by one (124314, ADS, SDK, etc)
MsgBox Mats(counter).SubMatches(0) & " " & Mats(counter).SubMatches(2) & " " & Mats(counter).SubMatches(3) & " " & Mats(counter).SubMatches(4)
Next