2
獲得比賽只要我有以下文字:VBA正則表達式 - 從多條線路
55,8%(1) – 3426 bytes used from 6kB
58,1%(2) – 3572 bytes used from 6kB
我想用以下模式:
^(\d\d,\d)(?:%\(\d\) .)(\d{3,4})(?:)(bytes)(?: used from)(\d{1,3})(?:kB)$
這裏是我使用的代碼:
Dim ramtext As String
ramtext = getTableCellText("1.7", 3, 2)
Dim regex As New RegExp
With regex
.Pattern = "^(\d\d,\d)(?:%\(\d\) .)(\d{3,4})(?:)(bytes)(?: used from)(\d{1,3})(?:kB)$"
.Global = 1
.MultiLine = 1
End With
Dim matches As MatchCollection
Set matches = regex.Execute(ramtext)
您確定一開始沒有垃圾字符嗎?嘗試在'^'後面加上'\ W *'。 (\ d {1,3})kB $「(\ d {3,4})(字節)中使用'\ W *(\ d \ d,\ d)%\ ' –
仍然一樣。如果你在regexr.com上試試這個,你會發現這個模式本身有效。而且regexr可以識別兩行(你需要在那裏設置multiline = true) – ThomasMX
你確定這些空格是正常的嗎?嘗試用'\ s'替換空格。嘗試'「^(\ d \ d,\ d)%\(\ d \)\ s。\ s(\ d {3,4})\ s(bytes)\ sused \ sfrom \ s(\ d {1 ,3})KB $「'。 –