[Haskell-cafe] regular expression sub-expression matching

Roman Cheplyaka roma at ro-che.info
Sat Jan 19 00:47:31 CET 2013


* Nicolas Bock <nicolasbock at gmail.com> [2013-01-18 16:25:31-0700]
> Hello list,
> 
> I was wondering whether there is a way to do what the following python code
> does in haskell:
> 
> import re
> 
> result = re.compile("M\(([0-9]+),([0-9]+)\) *=
> *([0-9.eE-]+);").search("M(1,2) = 0.1e-3;")
> if result:
>   print(result.group(1), result.group(2), result.group(3))
> 
> Basically I would like to pattern match parts of a string and return the
> matches. I have looked at Text.Regex.Posix but (of course I might just not
> have understood the functions in there properly) it seems as if it does not
> provide anything like python's re module.

Take a look at the regex-applicative package.

http://hackage.haskell.org/packages/archive/regex-applicative/0.2.1/doc/html/Text-Regex-Applicative.html

Roman



More information about the Haskell-Cafe mailing list