Does anyone have a function for doing a regex replace in Haskell? I found this: regex replace example but it is about 2 years old and doesn't compile on my machine (even after adding {-# OPTIONS_GHC -fglasgow-exts -fbang-patterns #-}), and I'm too lazy much of a newbie to work out how to fix it.
Also, I need a solution that uses the regex-pcre or pcre-light libraries, rather than regex-posix. Any help would be much appreciated.
Comments §
Both compile for me on 6.8.2 using "-fbang-patterns --make".
It's my understanding that regex-pcre should be a drop-in replacement for Text.Regex; I haven't used it, but based on the instances it defines according to hackage, using it with that old code should be pretty simple.
import Text.Regex(subRegex,mkRegex)
-- substitute x with y in s
substitute x y s = subRegex (mkRegex x) s y
I've found the cause of my bug (in vague terms): bytestring-0.9.1.0 causes the compilation failure. Rverting to 0.9.0.1 makes it work again.
Also: The number of imaginable replacement routines is quite large, and no general solution can also be efficient. Rolling you own is usually the right choice.