From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 89454BBAF for ; Mon, 6 Dec 2010 21:41:12 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApAAALPY/ExCbwQZkGdsb2JhbACVJY4XFQEBAQEJCQwHEQQevwWFSQSEX4ki X-IronPort-AV: E=Sophos;i="4.59,307,1288566000"; d="scan'208";a="69988371" Received: from out1.smtp.messagingengine.com ([66.111.4.25]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 06 Dec 2010 21:41:12 +0100 Received: from compute3.internal (compute3.nyi.mail.srv.osa [10.202.2.43]) by gateway1.messagingengine.com (Postfix) with ESMTP id CBC451B6 for ; Mon, 6 Dec 2010 15:41:10 -0500 (EST) Received: from frontend2.messagingengine.com ([10.202.2.161]) by compute3.internal (MEProxy); Mon, 06 Dec 2010 15:41:10 -0500 X-Sasl-enc: e115vNjMqIPp04XpjKTt0JsZDDoEV7M1W0XD/f5teB0p 1291668070 Received: from [192.168.1.206] (64-71-1-165.static.wiline.com [64.71.1.165]) by mail.messagingengine.com (Postfix) with ESMTPSA id 7EBD15E2886 for ; Mon, 6 Dec 2010 15:41:10 -0500 (EST) Message-ID: <4CFD4A83.60501@ens-lyon.org> Date: Mon, 06 Dec 2010 12:41:39 -0800 From: Martin Jambon User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20101023 Lightning/1.0b3pre Thunderbird/3.1.3 MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Re: help with regular expression References: <926418.88102.qm@web65410.mail.ac4.yahoo.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ens-lyon:01 regexp:01 pcre-ocaml:01 syntax:01 regexp:01 syntax:01 eol:01 enforces:01 pcre:01 pcre:01 quantifiers:01 aba:98 wrote:01 wrote:01 caml-list:01 On 12/06/10 05:11, Sylvain Le Gall wrote: > On 06-12-2010, David Allsopp 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