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!
text.gsub(/\[\w+\]/, Hash[search.zip replace])
# => "[B] and [C]"
text = "[A#] and [B]", search = ["[A#]", "[B]", "[C]", "[D]", "[Aa]"], replace = ["[B]", "[C]", "[D]", "[E]", "[Bb]"], and i still want to replace value of text to "[B] and [C]". How can i modify your method to use it?# to gsub part, like this: .gsub(/\[\w+\#*\]/,.gsub(/\[\w+#\]/, and i forgot * after #text.gsub(Regexp.union(search), search.zip(replace).to_h)