Using regexps to filter data

Not sure I'm even in the right neighborhood with this. Need to screen for integer data. Am I going about this correctly? 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> :m + Text.Regex.Base.RegexLike Prelude Text.Regex.Base.RegexLike> let r = makeRegex "[+-]?[0-9]+" <interactive>:1:8: No instance for (RegexMaker regex compOpt execOpt [Char]) arising from a use of `makeRegex' at <interactive>:1:8-30 Possible fix: add an instance declaration for (RegexMaker regex compOpt execOpt [Char]) In the expression: makeRegex "[+-]?[0-9]+" In the definition of `r': r = makeRegex "[+-]?[0-9]+" Prelude Text.Regex.Base.RegexLike>

Hi Michael I think you want to be using a one of the 'implementation' packages directly rather than Text.Regex.Base.RegexLike (from regex-base), for instance regex-posix. If you are searching a string you would want to import the Text.Regex.Posix.String module. Text.Regex.Base.RegexLike provides the interface, specific matchers (e.g. Posix or PCRE) provide the implementation. Best wishes Stephen

Thanks. Looks kind of complicated. Are there any examples of how to use this stuff?
Michael
--- On Mon, 3/15/10, Stephen Tetley

On 15 March 2010 14:02, michael rice
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

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
participants (2)
-
michael rice
-
Stephen Tetley