<span style>Hello,</span><div style><br></div><div style>I have a given piece of multiline HTML (which is generated using pandoc btw.) and I am trying to wrap certain elements (tags with a given class) with a &lt;div&gt;.</div>
<div style><br></div><div style>I already took a look at the Text.Regex.PCRE module which seemed a reasonable choice because I am already familiar with similar regex implementations in other languages.</div><div style><br>
</div><div style>I came up with the following function which takes a regex and replaces all matches within the given string using the provided function (which I would use to wrap the element)</div><div style><br></div><div style>
import Text.Regex.PCRE ((=~~))</div><div style><br></div><div style><div>-- Replaces the whole match for the given regex using the given function</div><div>regexReplace :: String -&gt; (String -&gt; String) -&gt; String -&gt; String</div>
<div>regexReplace regex replace text = go text</div><div>    where</div><div>        go text = case text =~~ regex of</div><div>            Just (before, match, after) -&gt;</div><div>                before ++ replace match ++ go after</div>
<div>            _ -&gt; text</div><div><br></div></div><div style>The problem with this function is, that it will not work on multiline strings. I would like to call it like this:</div><div style><br></div><div style>newBody = regexReplace &quot;&lt;table class=\&quot;sourceCode\&quot;.*?table&gt;&quot; wrap body</div>
<div style>wrap x = &quot;&lt;div class=\&quot;sourceCodeWrap\&quot;&gt;&quot; ++ x ++ &quot;&lt;/div&gt;&quot;</div><div style><br></div><div style>Is there any way to easily pass some kind of  multiline modifier to the regex in question?</div>
<div style><br></div><div style>Or is this approach completely off and would something else be more appropriate/haskelly for the problem at hand?</div><div style><br></div><div style>Thank you very much in advance.</div>