caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin.jambon@ens-lyon.org>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Re: help with regular expression
Date: Mon, 06 Dec 2010 12:41:39 -0800	[thread overview]
Message-ID: <4CFD4A83.60501@ens-lyon.org> (raw)
In-Reply-To: <slrnifpo81.ut5.sylvain@gallu.homelinux.org>

On 12/06/10 05:11, Sylvain Le Gall wrote:
> On 06-12-2010, David Allsopp <dra-news@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


  reply	other threads:[~2010-12-06 20:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-06 11:43 zaid khalid
2010-12-06 12:03 ` [Caml-list] " David Allsopp
2010-12-06 13:11   ` Sylvain Le Gall
2010-12-06 20:41     ` Martin Jambon [this message]
2010-12-06 17:31 ` Dawid Toton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CFD4A83.60501@ens-lyon.org \
    --to=martin.jambon@ens-lyon.org \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).