I need to found all strings in a Text paragraph; but I receive only the first occurrence.
This is the calling SUB:
Codice: Seleziona tutto
sub testRE()
Dim Stringa As String
stringa = "It indicate the Fontname and Fontsize of the index generated. We can add a Fontname not present in the list of Fontnames."
regex(stringa,"\bfonTname[a-zA-Z]?\b")
end sub
Codice: Seleziona tutto
Function regex(a, b as string) ' a - string or cell to search in ' b - regexp string or cell containing regexp string
oTextSearch = CreateUnoService("com.sun.star.util.TextSearch")
oOptions = CreateUnoStruct("com.sun.star.util.SearchOptions")
with oOptions
.algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP
.transliterateFlags = com.sun.star.i18n.TransliterationModules.IGNORE_CASE
.searchString = b
end with
oTextSearch.setOptions(oOptions)
oX = oTextSearch.searchForward(a, 0, Len(a))
oFound = oX.subRegExpressions
for c = 0 to oFound-1
print Mid(a, oX.startOffset(c) + 1, oX.endOffset(c) - oX.startOffset(c))
next
End Function
Thanks
John Rossati