[Haskell-cafe] String rewriting

Uwe Schmidt si at fh-wedel.de
Fri May 21 05:22:38 EDT 2010


Hi Roly,

> I'm looking for a simple way to rewrite strings according to simple
> composable rules like:
>
> replace "_" by "\\(\\hole\\)"
> replace "-n" where n matches an integer by "^{n}"
>
> so that I can import some pretty-printed output into a LaTeX alltt
> environment. I'm guessing that this nice functional stream
> transformation problem has been solved thousands of times. Could
> anyone point me to a simple package that would do this for me?

you can try the regex-xmlschema package

on Hackage: http://hackage.haskell.org/package/regex-xmlschema-0.1.3

-- ----------

import Text.Regex.XMLSchema.String

replace1 :: String -> String
replace1 = sed (const "\\(\\hole\\)") "_"

replace1 :: String -> String
replace2 = sed (\ x -> "^{" ++ x ++ "}") "-[0-9]+"

-- -----------

will solve your task

Regards,

  Uwe



More information about the Haskell-Cafe mailing list