Unable to find any useful documentation on regex in Libreoffice calc/basic.
I am trying to get all results of a matched regex expression. But it only ever returns the first result.
I’m pretty sure I need to specify the global option, but can’t figure out how…
Sub Test
Dim oTextSearch,oOptions,oFound,J,I
Dim sPhone() As String
oTextSearch = CreateUnoService("com.sun.star.util.TextSearch")
oOptions = CreateUnoStruct("com.sun.star.util.SearchOptions")
oOptions.algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP
oOptions.searchString = "[0-9,\\-]{8}"
oTextSearch.setOptions(oOptions)
oFound = oTextSearch.searchForward("h)999-9999 c)888-8888", 0, Len("h)999-9999 c)888-8888"))
J = -1
ReDim sPhone() As String
For I = 1 to oFound.subRegExpressions
J = J + 1
ReDim Preserve sPhone(J)
sPhone(J) = mid("h)999-9999 c)888-8888", oFound.startOffset(I-1)+1, oFound.endOffset(I-1) - oFound.startOffset(I-1))
Next I
End Sub
Edited by @Lupp
Please use the tool Preformatted text (Ctrl+E)
for code.
If you want to reject my changes, edit again.