From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA01130; Fri, 27 Sep 2002 10:14:44 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA01129 for ; Fri, 27 Sep 2002 10:14:43 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g8R8Eb529139; Fri, 27 Sep 2002 10:14:37 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA01123; Fri, 27 Sep 2002 10:14:36 +0200 (MET DST) Date: Fri, 27 Sep 2002 10:14:36 +0200 From: Xavier Leroy To: Maxence Guesdon Cc: "Kontra, Gergely" , caml-list@inria.fr Subject: Re: [Caml-list] (Sorry for my last post) lazyness, exceptions?, ocaml syntax rule-of-thumbs Message-ID: <20020927101436.A911@pauillac.inria.fr> References: <20020927100115.5ab3fec6.maxence.guesdon@inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20020927100115.5ab3fec6.maxence.guesdon@inria.fr>; from maxence.guesdon@inria.fr on Fri, Sep 27, 2002 at 10:01:15AM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > Another annoying problem (maybe it is in the docs...), but I cannot find > > a function, which checks, whether a string can match a regexp, and > > return true or false. Search_forward, again, I think should be return an > > option, and not trowing an exception. > > See Str.string_match : regexp -> string -> int -> bool In an attempt to prevent one more round of e-mails on this topic, let me just add that string_match performs "anchored matching" (matching the RE at the given location in the string) while search_forward performs "unanchored matching" (matching at any location). However, the latter can be turned into the former by prefixing the regexp with ".*". Hence, the following are equivalent: Str.string_match (Str.regexp ".*\\.html$") filename 0 and try ignore(Str.search_forward (Str.regexp "\\.html$") filename 0); true with Not_found -> false This said, a much cleaner solution is Filename.check_suffix filename ".html" Not only it is shorter, but under Windows it will perform case-insensitive matching, like it should. - Xavier Leroy ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners