JRegex is a library that provides interfaces to both PCRE (perl comptatable regular expressions) and Posix regular expressions. it also provides an operator (=~) which is similar, but much more powerful than the perl operator. In addition, the syntax uses extensible type classes so you may extend it with any regular expression or list matching types and the ability to match lists of any type (not just chars). for an example, here is the output of several calls to =~ just used at different types: -- return number of times the regex matches print ("hellofooobarbobfoobarbad" =~ "fo*bar" :: Int) => 2 -- returns the first matching expression print ("hellofooobarbobfoobarbad" =~ "fo*bar" :: String) => "fooobar" -- returns the string before the first match, the matching string, and the string after the first match print ("hellofooobarbobfoobarbad" =~ "fo*bar" :: (String,String,String)) => ("hello","fooobar","bobfoobarbad") -- returns true if there is a match at all and false otherwise print ("hellofooobarbobfoobarbad" =~ "fo*bar" :: Bool) => True -- always returns (). useful with the (=~~) monadic operator print ("hellofooobarbobfoobarbad" =~ "fo*bar" :: ()) => () -- returns all matching substrings print ("hellofooobarbobfoobarbad" =~ "fo*bar" :: [String]) => ["fooobar","foobar"] -- returns an array off all matching parenthesised substrings in the regex for first match print ("hellofooobarbobfoobaaarbad" =~ "f(o*)b(a+r)" :: Array Int String) => array (0,2) [(0,"fooobar"),(1,"ooo"),(2,"ar")] -- returns an array off all matching parenthesised substrings in the regex for all matches print ("hellofooobarbobfoobaaarbad" =~ "f(o*)b(a+r)" :: [Array Int String]) => [array (0,2) [(0,"fooobar"),(1,"ooo"),(2,"ar")],array (0,2) [(0,"foobaaar"),(1,"oo"),(2,"aaar")]] here is its homepage: http://repetae.net/john/computer/haskell/JRegex/ I released a different version of this library in the past, but this version has been cleaned up, moved to a proper spot in the libraries, and is cabalized. John -- John Meacham - ⑆repetae.net⑆john⑈
participants (1)
-
John Meacham