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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id E41B77EFCD for ; Wed, 1 Oct 2014 18:28:17 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of Xavier.Leroy@inria.fr) identity=pra; client-ip=212.27.42.5; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="Xavier.Leroy@inria.fr"; x-sender="Xavier.Leroy@inria.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of Xavier.Leroy@inria.fr) identity=mailfrom; client-ip=212.27.42.5; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="Xavier.Leroy@inria.fr"; x-sender="Xavier.Leroy@inria.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@smtp5-g21.free.fr) identity=helo; client-ip=212.27.42.5; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="Xavier.Leroy@inria.fr"; x-sender="postmaster@smtp5-g21.free.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqsBAG4qLFTUGyoFnGdsb2JhbABghzzLZoMhAoEMFgERAQEBAQEGDQkJFCyEAwEBAQMBIzAlBgsLGAICBRYLAgIJAwIBAgFFEwgBAYgyDKhylXmBLI8BFoJigVMBBJhohEuHWJIAgzQBAQE X-IPAS-Result: AqsBAG4qLFTUGyoFnGdsb2JhbABghzzLZoMhAoEMFgERAQEBAQEGDQkJFCyEAwEBAQMBIzAlBgsLGAICBRYLAgIJAwIBAgFFEwgBAYgyDKhylXmBLI8BFoJigVMBBJhohEuHWJIAgzQBAQE X-IronPort-AV: E=Sophos;i="5.04,633,1406584800"; d="scan'208";a="98874742" Received: from smtp5-g21.free.fr ([212.27.42.5]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 01 Oct 2014 18:28:17 +0200 Received: from [192.168.1.2] (unknown [82.237.71.191]) by smtp5-g21.free.fr (Postfix) with ESMTP id AA977D4807F for ; Wed, 1 Oct 2014 18:27:37 +0200 (CEST) Message-ID: <542C2BA0.8020900@inria.fr> Date: Wed, 01 Oct 2014 18:28:16 +0200 From: Xavier Leroy User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: caml-list@inria.fr References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Str, regular expressions, longest match On 29/09/14 22:04, Tom Ridge wrote: > I am trying to use the Str module to match regular expressions. I want to > return the longest match.[...] I don't want the order of > the alternatives to matter. What am I doing wrong? Nothing: it's just that Str has first-match semantics, not longest-match. > What can I do to match the longest substring? In this particular example, you can sort the string patterns in decreasing lexicographic order before putting them in ...|...|... In more general case, you might have more luck with other regexp libraries (e.g. PCRE or Vouillon's RE, but I didn't check whether they implement longest match). Hope this helps, - Xavier Leroy