
Found this tutorial: http://www.serpentine.com/blog/2007/02/27/a-haskell-regular-expression-tutor...
Seems to work for what I need to do.
Michael
=========
[michael@localhost ~]$ ghci
GHCi, version 6.10.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> :mod +Text.Regex.Posix
Prelude Text.Regex.Posix> "bar" =~ "(foo|bar)" :: Bool
Loading package syb ... linking ... done.
Loading package array-0.2.0.0 ... linking ... done.
Loading package bytestring-0.9.1.4 ... linking ... done.
Loading package regex-base-0.72.0.2 ... linking ... done.
Loading package regex-posix-0.72.0.3 ... linking ... done.
True
Prelude Text.Regex.Posix> "-123" =~ "\-?[0-9]+" :: Bool
<interactive>:1:13:
lexical error in string/character literal at character '?'
Prelude Text.Regex.Posix> "-123" =~ "[+-]?[0-9]+" :: Bool
True
Prelude Text.Regex.Posix> "+123" =~ "[+-]?[0-9]+" :: Bool
True
Prelude Text.Regex.Posix> "abc" =~ "[+-]?[0-9]+" :: Bool
False
Prelude Text.Regex.Posix>
--- On Mon, 3/15/10, Stephen Tetley
Thanks. Looks kind of complicated. Are there any examples of how to use this stuff?
Hi Michael I'm note sure, I haven't used the Regex package since it was moved out of the libs distributed with GHC. I think the multiple backends were added after this, and it was extended so matching could work on ByteStrings as well as Strings. PCRE-light is a simpler alternative, if you can live with PCRE style regexs rather than Posix ones: http://hackage.haskell.org/package/pcre-light Best wishes Stephen