Search and replace in specific order

Hello. I need to replace the contents of multiple cells. I’m using find and replace for this, but the problem is that I need to perform multiple searches with multiple replacements.

Let me explain: I want it to search for a word and replace it with the word specified in the replace field. For example, word1 is replaced by string1, word2 by string2, and so on.

Example:
Find: word1|word2|word3|word4
Replace: string1|string2|string3|string4

This was discussed in another post How find and replace multiple values ? - #2 by RGB-es by user thisc00, but it went unanswered. I hope this clarifies the issue, although I think the solution requires creating a macro , but I’m not an expert in that area.

Regards

Do you want multiple words replaced at the same time automatically (multi-find & multi-replace)?

The appropriate means should be RegularExprerssion, and it can search for a list of alternative strings, but it can not replace the findings depending on which one of the alternatives was found.
(You may study https://www.rexegg.com/ if you hope for a workaround.)

IMO the means of choice for a rather complicated job of the kind you seem to have, is UserCode. See example:
multiReplacement_129651_RAWsloppy.ods (13.8 KB)

1 Like

See this tutorial, this may help:

A macro could be used if you are replacing the same text with the same replacement every time. I use just such a macro to transpose chord charts to different keys in writer regularly. However my macro is too complex for the simple search replace that you are suggesting

?? I read the thread and there are two answers:

  • rgb-es wrote it is not possible in LibreOffice, because there are no regular expressions in the replace box
  • Earendil suggested an extension (I guess. I am familiar with AltSearch, but not with the named AltSearchandbreplace /EDIT seems to be the same)

The actual problem is: The linked thread is for Writer, and the extension names also Writer, while you tagged Calc.
.
As conclusion I would probably use a macro. For an easy start use the macro-recorder to record one (global?) search and replace, then edit from there.
Main question is then: Do you use always the same list, or shell the macro ask for input of word1 etc first.

Did you check the user code contained in the example attached to my post Search and replace in specific order - #3 by Lupp

The mentioned attachment contained rather sloppy code. I tidied it up and attach the new version now.

multiReplacement_129651_tidied.ods (16.5 KB)