Ask Your Question

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

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

Stephanium Lupis gravatar image

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

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 +0200

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 +0200 )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 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 1,370 times

Last updated: Jun 13 '16