# Is it possible to use a regular expression in the Replace box in LibreOffice Calc?

This question has been asked several times in the past with no answer to date. It seems actually there's an unresolved issue in LibreOffice Calc that prevents using regular expressions in the Replace box. For instance, you can enter regex codes for tabs, spaces, linefeeds, etc. (\t, \s, \n) in the Find box but you cannot use them in the Replace box - they are treated literally. Any ideas or suggestions?

edit retag close merge delete

Sort by » oldest newest most voted

No it is not possible; and using regular expressions in replacement field actually does not make sense: regular expression is a mask that should match something in searched text - something not suitable for replacement text. It doesn't make sense to use \s there (meaning "insert unspesified spacing character"). It is possible to use \n and back references, though.

What you are asking about is not using regular expressions in replacement field - but rather having ways to express some specific characters there that have dedicated syntax in regular expressions, like unicode codepoints, but aren't accepted in replace field. You are welcome to file an enhancement request.

more

See bug report (enhancement request) tdf#106137.

( 2019-05-12 14:16:45 +0200 )edit

But of course certain regexp can be used in the replace box and they appear to work in calc. e.g. "&" might be useful.The help page tells you which ones work.

( 2019-05-12 18:54:08 +0200 )edit

"&" isn't a special character for RegeEx. It's one of the "special characters" introduced only for the replace string. In addition (afaik) the special usage of the character "$" followed by a decimal digit in OO/LibO is rather uncommon. Mostly the backslash is used in this role like in back-references to groups found in RegEx. The usage of "$" for "end of text" (text being a paragraph in this context in OO) in the search sting also seems to be uncommon. AltSearch uses "\p" for the purpose which seems more "intuitive" to me. To use "$" in the two mentioned very different roles i would consider definitely a bad idea. Even worse is "\n" inserting a paragraph break if used in the replace string. ( 2019-05-12 19:40:13 +0200 )edit I have the same problem on Ubuntu 19.10 The character $ detects the end of paragraphs but \n or \t don't work in Find or Replace.

more