Ask Your Question

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

asked 2016-06-13 10:58:47 +0100

Stephanium Lupis gravatar image

updated 2016-06-13 11:09:31 +0100

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
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2016-06-13 11:36:12 +0100

erAck gravatar image

You can use the com::sun::star::XTextSearch interface (obtained from service) with SearchOptions.algorithmType set to com::sun::star::util::REGEXP, see and linked types.

edit flag offensive delete link more


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

lomacar gravatar imagelomacar ( 2018-07-26 13:45:51 +0100 )edit

As the XTextSearch interface is provided by the service, searching for"TextSearch..." reveals the first hit

erAck gravatar imageerAck ( 2018-07-26 16:27:47 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-06-13 10:58:47 +0100

Seen: 856 times

Last updated: Jun 13 '16