[Haskell-cafe] why no replace function in our regular expression libs ?

Albert Y. C. Lai trebla at vex.net
Sat Jan 26 00:53:40 CET 2013


On 13-01-25 02:06 PM, Simon Michael wrote:
> People have put a lot of work into regular expression libraries on
> haskell. Yet it seems very few of them provide a replace/substitute
> function - just regex-compat and regepr as far as I know. Why is that ?
[...]
> Secondly, as of today what do y'all do when you need that functionality

I can only speak for myself, why I do not miss regex substitution too much.

Sometimes, regex substitution is exactly the solution, and I use it. But 
the whole job is easily done in a shell script, or even in an editor. So 
I don't use regex substitution in Haskell in this case.

Sometimes, the substitution job is: transform this

   <article>
   <title><code>Monad</code> Tutorial</title>
   <content>...</content>
   </article>

to this

   <!DOCTYPE html etc etc>
   <html>
   <head><title>Monad Tutorial</title></head>
   <body>
     <h1><code>Monad</code> Tutorial</h1>
     ...
   </body>
   </html>

In this job, if a regex solution exists, I don't want to know. I just 
use HXT or XSLT.

Sometimes, regex substitution plus Haskell is exactly the solution. Then 
I use regex-compat. It works. One solution is enough. I don't need a 
hundred choices for regex, or a hundred choices for Int.



More information about the Haskell-Cafe mailing list