Apparently while this would be supported by default by almost all modern languages it’s not the case with Haskell. I tried several regex libraries which either didn’t support substitutions or couldn’t handle unicode properly.
import qualified Text.Regex.PCRE.Light as RL import qualified Text.Regex.PCRE.Heavy as RH -- Find and replace bare youtube links separated by <p></p>. youtubeFilter :: String -> String youtubeFilter txt = RH.gsub rx replace txt where rx = RL.compile "<p>\\s*https?://www\\.youtube\\.com/watch\\?v=([A-Za-z0-9_-]+)\\s*</p>" [RL.utf8] replace = \[g] -> "<div class=\"video-wrapper\">\ \<div class=\"video-container\">\ \<iframe src=\"//www.youtube.com/embed/" ++ g ++ "\" frameborder=\"0\" allowfullscreen/>\ \</div>\ \</div>";
Which is to say it’s not very elegant but it does get the job done.