
Hi, 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,0,0,0],"METABOLISM"). class([1,1,0,0],"amino-acid metabolism"). class([1,1,1,0],"amino-acid biosynthesis"). Amanda -- Amanda Clare http://users.aber.ac.uk/ajc99/ Tel: +44 (0)1970 621922 Fax: +44 (0)1970 622455 Dept. of Computer Science, University of Wales, Aberystwyth, SY23 3DB

On 2001-07-11T15:41:28+0100, Amanda Clare wrote:
let exp = mkRegex "^class\(\[(.*)\]," in
I think you need to use two backslashes instead of one. The reason is that the lexical syntax of Haskell needs two backslashes to represent a single backslash (which is in turn interpreted by the regular expression compiler). -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig "There isn't anyone out there who isn't Seymour's fat lady."

Ken Shan wrote:
On 2001-07-11T15:41:28+0100, Amanda Clare wrote:
let exp = mkRegex "^class\(\[(.*)\]," in
I think you need to use two backslashes instead of one.
Thanks, that's great, it works. However a simple match of this pattern against "class([1,0,0,0],\"METABOLISM\")." gives me ["1,0,0,0","","","","","","","","","","","","","","","","","","","","","","","","","","","",""] ie the right answer, and 28 other empty answers. The documentation says "Note that there may be more components in the returned list than were in the pattern, and that any component which either matched the empty string or wasn't matched at all (because it was part of an optional part of the pattern), will be empty." Does this mean I had 28 matches with the empty string? Why are they returned? Will I always have to filter all these null strings out of every result? Will the result I want always be first? Amanda -- Amanda Clare http://users.aber.ac.uk/ajc99/ Tel: +44 (0)1970 621922 Fax: +44 (0)1970 622455 Dept. of Computer Science, University of Wales, Aberystwyth, SY23 3DB
participants (2)
-
Amanda Clare
-
Ken Shan