From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id B3C407FACD for ; Mon, 29 Sep 2014 22:04:39 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of tom.j.ridge@googlemail.com) identity=pra; client-ip=209.85.216.171; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="tom.j.ridge@googlemail.com"; x-sender="tom.j.ridge@googlemail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of tom.j.ridge@googlemail.com designates 209.85.216.171 as permitted sender) identity=mailfrom; client-ip=209.85.216.171; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="tom.j.ridge@googlemail.com"; x-sender="tom.j.ridge@googlemail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qc0-f171.google.com) identity=helo; client-ip=209.85.216.171; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="tom.j.ridge@googlemail.com"; x-sender="postmaster@mail-qc0-f171.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AssBAL66KVTRVdirlGdsb2JhbABghDgEgn3PeAgWAREBAQEBBwsLCRIug3oiER0BATgQDQEHNwIkEgEFASI1iAcBAxGdNm6KOHiFAgEFiH4KGScNhyAGkx2BU5hihEuTaxgpgWyDKTwvgkoBAQE X-IPAS-Result: AssBAL66KVTRVdirlGdsb2JhbABghDgEgn3PeAgWAREBAQEBBwsLCRIug3oiER0BATgQDQEHNwIkEgEFASI1iAcBAxGdNm6KOHiFAgEFiH4KGScNhyAGkx2BU5hihEuTaxgpgWyDKTwvgkoBAQE X-IronPort-AV: E=Sophos;i="5.04,622,1406584800"; d="scan'208";a="81314379" Received: from mail-qc0-f171.google.com ([209.85.216.171]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 29 Sep 2014 22:04:38 +0200 Received: by mail-qc0-f171.google.com with SMTP id i17so2728679qcy.30 for ; Mon, 29 Sep 2014 13:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:sender:from:date:message-id:subject:to:content-type; bh=IbCOYqH8rYk6vruINJmDN3EA2gmAqNkB7KvwbGNeHrM=; b=YKDNNLdf1k3BiropwPAmgZW2MZNw9YZmmxRo5KFC5J6zXLSsYrNQPsx/pAB64HA4I0 TFoCqpa0bKmP5YGIZBe+96C7U6oFnPfiTo35ly5TezDZUk19VZ/90XKNItmFmzPqQTuW gqDD64IT1bGA99oPIh2n+XIuIj2YPq1GGDhTkp4ZuDjbQAG3mNOXn2xBVyg4JFhClY9n LAJdymYpY7J6l/jK8DBNgeQPQ6ITD7dla9qtCHYSZAMLYtoErWI3nkGaoJ821nsBf/XH Y3OPbsTg0FFnAhmsEn8sDgteOEacDYaYkWQ3COTDG64zaQe6uGXef4ZJeiraukM79yyh 4dmg== X-Received: by 10.140.96.104 with SMTP id j95mr4806898qge.106.1412021077798; Mon, 29 Sep 2014 13:04:37 -0700 (PDT) MIME-Version: 1.0 Sender: tom.j.ridge@googlemail.com Received: by 10.140.156.3 with HTTP; Mon, 29 Sep 2014 13:04:17 -0700 (PDT) From: Tom Ridge Date: Mon, 29 Sep 2014 21:04:17 +0100 X-Google-Sender-Auth: AXsyVYGzUBeYZn3otmHtgisYAL8 Message-ID: To: caml-list Content-Type: multipart/alternative; boundary=001a113aac1ec200fe050439c61a Subject: [Caml-list] Str, regular expressions, longest match --001a113aac1ec200fe050439c61a Content-Type: text/plain; charset=UTF-8 Dear All, I am trying to use the Str module to match regular expressions. I want to return the longest match. let txt = "ab" let reg = "a\\|ab" let _ = let b = Str.string_match (Str.regexp reg) txt 0 in Str.matched_string txt After the last line, the string "a" is apparently matched. But I hope that the result should be "ab". If I reverse the order of the alternatives in the regular expression, the string "ab" is matched. I don't want the order of the alternatives to matter. What am I doing wrong? What can I do to match the longest substring? Thanks Tom --001a113aac1ec200fe050439c61a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Dear All,

I am trying to use the Str mo= dule to match regular expressions. I want to return the longest match.

let txt =3D "ab"
let reg= =3D "a\\|ab"
let _ =3D=C2=A0
=C2=A0 let b = =3D Str.string_match (Str.regexp reg) txt 0 in
=C2=A0 Str.matched= _string txt

After the last line, the s= tring "a" is apparently matched. But I hope that the result shoul= d be "ab". If I reverse the order of the alternatives in the regu= lar expression, the string "ab" is matched. I don't want the = order of the alternatives to matter. What am I doing wrong? What can I do t= o match the longest substring?

Thanks
Tom
--001a113aac1ec200fe050439c61a--