Let's say I have a string I want to modify:
str = "I have several paints. For example, red, green, and blue."
I want to turn it into: I have several paints. For example, XXX, XXX, and blue.
So I have a list of words to replace with XXX:
colors = ["red", "green"]
I want to replace the colors from colors in str. Here's what I have so far:
- First, a function to replace something with "xxx":
subColor pat str = subRegex (mkRegex pat) str "xxx" - Next, I'm trying to map that or fold it over the list of colors. But I'm stuck:
mapjust returns copies of the string, each with a single word replaced, and I've been getting errors withfoldl. What am I doing wrong?
Edit: I should also say that I will sometimes have multi-line words, so using words (as suggested in another similar question's answers) isn't really practical for me.
Edit2: I should add that one big regex pattern, like blue|red probably wouldn't work for me either, since I actually have several thousand of these things to replace.
foldr subColor str colors