[Haskell-beginners] wrapping text in a multiline string

Chaddaï Fouché chaddai.fouche at gmail.com
Thu Jun 7 17:34:23 CEST 2012

On Wed, Jun 6, 2012 at 10:08 PM, Rico Moorman <rico.moorman at gmail.com> wrote:
> If this is correct ... I am still a little lost though. I cannot come
> up with a way of matching the actual String out of the MatchText
> returned by matchOnceText ...
> http://hackage.haskell.org/packages/archive/regex-base/latest/doc/html/Text-Regex-Base-RegexLike.html#v:matchOnceText

MatchText is an array, which allows for captures in the regex, for
instance, if matching "hello Abel ! And goodbye." with "hello (\w+)
([.!?])", MatchText would be :

array (0,2) [(0,("hello Abel !",(0,12))), (1,("Abel",(6,4))), (2,("!",(11,1)))]

So if you want the whole matched text, you would use :

> fst (match ! 0)

Or you could just use matchM :

>        go text = case RE.matchM regex' text of
>           Just (before, match, after) ->
>               before ++ replace' match ++ go after
>           _ -> text

and have match be a string, just like before (since you don't use all
the power of MatchText anyway).


More information about the Beginners mailing list