Amanda Clare
Wed, 11 Jul 2001 15:41:28 +0100


I'd like to use regular expressions in my code, so I looked at the ghc
documentation on this library and it doesn't say much. RegexString looks
great but I don't know how to use it. Some examples would be greatly
appreciated! Regex itself has even less documentation. From RegexString:

"mkRegex makes a regular expression with the default options
(multi-line, case-sensitive), whereas mkRegexWithOpts takes the values
for these options as parameteres. The syntax of regular expressions is
otherwise that of Perl."

Then what's wrong with

  let exp = mkRegex "^class\(\[(.*)\],"  in 

This would be the Perl syntax for the regexp.

It says
ghc  -package text   -c -o RegT.o RegT.hs
RegT.hs:13: error in character literal

I checked and it doesn't like the escaped ( [ and ]. So how do I escape
them? The unescaped inner round brackets mean that I want to collect the
result of this match, whereas the escaped brackets mean that these are
actual characters I want to match. My text to match looks like this:

class([1,1,0,0],"amino-acid metabolism").
class([1,1,1,0],"amino-acid biosynthesis").

Amanda Clare
Tel: +44 (0)1970 621922  Fax: +44 (0)1970 622455
Dept. of Computer Science, University of Wales, Aberystwyth, SY23 3DB