[Caml-list] Re: help with regular expression

2010-12-06 Thread Sylvain Le Gall
On 06-12-2010, David Allsopp dra-n...@metastack.com wrote:
 zaid Khalid wrote:


 Hint I am using (Str.regexp)

 There are other libraries (e.g. pcre-ocaml) which provide different (I
 would say more powerful, rather than strictly better!)
 implementations.



There is also syntax extension like mikmatch, that helps to write regexp
in a very meaningful syntax:

match str with 
| RE bol a* | ab* eol -
  true
| _ -
  false

http://martin.jambon.free.fr/mikmatch-manual.html
http://martin.jambon.free.fr/mikmatch.html

You can use pcre and str with mikmatch.

Regards,
Sylvain Le Gall

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] Re: help with regular expression

2010-12-06 Thread Martin Jambon
On 12/06/10 05:11, Sylvain Le Gall wrote:
 On 06-12-2010, David Allsopp dra-n...@metastack.com wrote:
 zaid Khalid wrote:


 Hint I am using (Str.regexp)

 There are other libraries (e.g. pcre-ocaml) which provide different (I
 would say more powerful, rather than strictly better!)
 implementations.


 
 There is also syntax extension like mikmatch, that helps to write regexp
 in a very meaningful syntax:
 
 match str with 
 | RE bol a* | ab* eol -
   true
 | _ -
   false

If I understand correctly the original problem, the solution is:

match str with
  | RE (a* | aba*) eos -
  (* matches always the beginning of the string,
 eos enforces a match at the end of the string,
 and the vertical bar has the lowest priority
 and so parentheses are needed. *)
  true
  | _ -
  false


 http://martin.jambon.free.fr/mikmatch-manual.html
 http://martin.jambon.free.fr/mikmatch.html
 
 You can use pcre and str with mikmatch.

I would recommend the pcre variant mostly for one feature that is not
provided by str:  lazy quantifiers, i.e. repeat as little as possible
before trying to match what comes next.


Martin

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs