Reputation: 2136
My case:
text = "[A] and [B]"
search = ["[A]", "[B]", "[C]", "[D]", "[Aa]"]
replace = ["[B]", "[C]", "[D]", "[E]", "[Bb]"]
i want to replace value of text
to "[B] and [C]"
How can i do that? Thanks a lot!
Upvotes: 3
Views: 90
Reputation: 29124
text.gsub(/\[\w+\]/, Hash[search.zip replace])
# => "[B] and [C]"
Upvotes: 8