I'm writing a function that takes a text as input, and perform replacements in the text. For instance, I look for all the instances of "blue" and replace that with "red". I use regexp to detect the strings I'm looking for, which is used by the (text).replace function. The problem is that I do a very high number of those text.replace, and I want a way to parse through the text string by string, and if it matches anything I want, I'll perform the replacement (instead of looking for "blue" in the entire text, then "green" in the entire text, and so on). I believe this is way more efficient, but how can I do this exactly?
Thanks in advance.