How to use replace to replace two words in a paragraphe

i want to replace two words using replace but i’m unable to do that

{{ replace “Batman and Robin” “Robin” “Catwoman” }} or {{ replace “hyde and jekyll” “jekyll” “Hugo” }}

i have tried or but it didn’t work

You can use Regex. {{ replaceRE "(Batman)|(Robin)" ... }}. Is that what you’re looking for?

thanks for your reply, but i want to replace both robin and jekyll in the same line

Oh so, do you mean you want to replace the following strings:

Batman and Robin, Robin, Catwoman or hyde and jekyll, jekyll, Hugo?

It can work something like:

{{ replaceRE "(Batman and Robin)|(Robin)|(Catwoman)|{hyde and jekyll)|(jekyll)|(Hugo)" ... }}

Sadly, I’m having trouble understanding how exactly you want the text to be grouped. But, I can explain my code in my previous answer so you can just modify and use it:

(...) anything between those brackets would be marked as an entire group. So, if you want to find the entire phrase foo plus bar, you can use it like (foo plus bar).

| is the or separator. It will stand for anything before or after that. For example, if you want to search for foo or bar, you can use it like foo|bar.

Does that help?

this one is working perfectly >>> {{ (replace $name “teaching-and-academics” “academics” ) }}

now i also want to replace ( “photography-and-video” “photography”) that are in the same line

i’ve tried that but it didn’t work :pensive:

{{ (replace $name ("teaching-and-academics" "academics") | ("photography-and-video" "photography") |}}

Try nesting two replace calls. The inner call becomes the input to the outer call.

{{ replace (replace $name "teaching-and-academics" "academics") "photography-and-video" "photography" }}
1 Like