[Haskell-cafe] Re: Has anybody replicated =~ s/../../ or even something more basic for doing replacements with pcre haskell regexen?

ChrisK haskell at list.mightyreason.com
Thu Mar 12 20:19:00 EDT 2009


Thomas Hartman wrote:
> Is there something like subRegex... something like =~ s/.../.../ in
> perl... for haskell pcre Regexen?
> 
> I mean, subRegex from Text.Regex of course:
> http://hackage.haskell.org/cgi-bin/hackage-scripts/package/regex-compat
> 
> Thanks for any advice,
> 
> thomas.

Short answer: No.

This is a FAQ.  The usual answer to your follow up "Why not?" is that the design 
space is rather huge.  Rather than justify this statement, I will point at the 
complicated module:

http://hackage.haskell.org/packages/archive/split/0.1.1/doc/html/Data-List-Split.html

The above module is "a wide range of strategies for splitting lists", which is a 
much simpler problem than your subRegex request, and only works on lists.  A 
subRegex library should also work on bytestrings (and Seq).

At the cost of writing your own routine you get exactly what you want in a 
screen or less of code, see
http://hackage.haskell.org/packages/archive/regex-compat/0.92/doc/html/src/Text-Regex.html#subRegex
for "subRegex" which is 30 lines of code.

Cheers,
   Chris



More information about the Haskell-Cafe mailing list