Ask Your Question
0

[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
0

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

erAck gravatar image

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/r... and linked types.

edit flag offensive delete link more

Comments

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 com.sun.star.util.TextSearch service, searching for https://duckduckgo.com/?q="TextSearch..." reveals the first hit https://stackoverflow.com/questions/2...

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

Question Tools

1 follower

Stats

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

Seen: 856 times

Last updated: Jun 13 '16