Search all items by Regular expression

Creare una macro - Scrivere uno script - Usare le API
Rispondi
Rossati
Messaggi: 8
Iscritto il: domenica 14 ottobre 2012, 9:24

Search all items by Regular expression

Messaggio da Rossati »

Hello

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
The function with the search is:

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
To be precise, there was a time when it worked.

Thanks

John Rossati
OpenOffice 3.4.1 Window 7
patel
Volontario attivo
Volontario attivo
Messaggi: 4030
Iscritto il: venerdì 30 aprile 2010, 8:04
Località: Livorno

Re: Search all items by Regular expression

Messaggio da patel »

This is the italian forum, maybe it's better for you http://forum.openoffice.org/en/forum/viewforum.php?f=20
-------------------
Libre Office 7.5.3.2 su Windows 11
allega un file di esempio, guadagnerai tempo tu e lo farai risparmiare a chi ti aiuta
Rispondi