Multiple replace what is the best solution to manage a large amount of replacements?

@admin @Timo @Plankton @ulrich @thecoder2012

Hi I search a solution to menage multiple replacements in fast and easy way.

I think to create 2 different array with the first array with the terms to find and a second array with the terms to replace.

Any suggestion to create a fast solution to manage multiple replacements ?

Use javascript’s .replace() method, stringing multiple replace’s together. ie:

var somestring = "foo is an awesome foo bar foo foo"; //somestring lowercase
var replaced = somestring.replace(/foo/g, "bar").replace(/is/g, "or");
// replaced now contains: "bar or an awesome bar bar bar bar"

This code will be run inside executescript_sandbox with ${in} and ${out} variables.

  • executescript_sandbox | var somestring = ${in}; var replaced = somestring.replace(/foo/g, “bar”).replace(/is/g, “or”); return replaced | out
1 Like

@admin @Timo @Plankton @ulrich @thecoder2012

If i have a long list of terms to replace how can i do this

example i have var ${pet} i need to convert values inside the var with this list (first element replaced with first element, second element replaced with second element …)

FROM
gatto
cane
cavallo
orso
uccello
gorilla
pesce
gabbiano
squalo
coniglio

TO
cat
dog
horse
bear
bird
gorilla
fish
seagull
shark
rabbit

Exist a fast way solution to muliple replacement in same times ?

Thanks

Are there only 10 elements to replace? Then I would do it like this:

somestring.replace(/old1/g, "new1").replace(/old2/g, "new2").replace(/old3/g, "new3")... => 10 chained replace commands :slight_smile:

1 Like

I search a fast way to add unlimited replacement.

I need it to replace value saved in variables for example to putting value in sites translated into several languages it’s more easy to save one value and after traslate the value inside the variable via macro code.

I search the fast way to do this, actually i know how to replace 1 single value for time but this create a long macro code (and slow) I prefer a short and fast way.

Can you post an example of your code adding a variable !COL1 inside the value to replace please ?

Thanks

Solved with your suggestion, very good thanks :slight_smile:

Sorry if I took a bit of time but I know little about javascript but reading your post I understood how to create the code