Provided that I have the following text:
55,8%(1) – 3426 bytes used from 6kB
58,1%(2) – 3572 bytes used from 6kB
I would like to use the following pattern:
^(\d\d,\d)(?:%\(\d\) . )(\d{3,4})(?: )(bytes)(?: used from )(\d{1,3})(?:kB)$
It returns matches only from the second line. But I want it to get matches from both lines :
Here is the code which I use:
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)
The solution was the following.
At the end of the first line, there is a newline character. In the document editor (outside VBA) newlines are not represented with vbNewLine, but it is a character of number 13. Those two are not the same, and for regexing vbNewLine must be used. So I had to replace it with vbNewLine.
ramtext = Replace(text, Chr(13), vbNewLine)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.