[Calc Macro] How to replace string with a regular expression?

Chances are low but is there a way to replace string using regular expressions?

str = "String  with a    multiple  spaces"
str = ReplaceRegex(str,"\s+"," ") REM "String with a multiple spaces"

Function ReplaceRegex(Str As String, Regex As String, Replacement As String)
    ReplaceRegex = ?
End Function

You can use the com::sun::star::XTextSearch interface (obtained from com.sun.star.TextSearch service) with SearchOptions.algorithmType set to com::sun::star::util::REGEXP, see http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1util_1_1XTextSearch.html and linked types.

The documentation provides no examples to show how to use XTextSearch. Could you?

As the XTextSearch interface is provided by the com.sun.star.util.TextSearch service, searching for "TextSearch" "LibreOffice" at DuckDuckGo reveals the first hit Using regex in a libreoffice calc macro to extract text from parentheses in a cell - Stack Overflow