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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 27FF7BBAF for ; Mon, 6 Dec 2010 12:50:00 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjsEAIRc/ExiizT6gGdsb2JhbACUbTGOKQEBCwsKBRMDH60rghmEJ4kEAQQEAYVEBIRfiSI X-IronPort-AV: E=Sophos;i="4.59,305,1288566000"; d="scan'208";a="82075962" Received: from nm30-vm0.bullet.mail.ac4.yahoo.com ([98.139.52.250]) by mail4-smtp-sop.national.inria.fr with SMTP; 06 Dec 2010 12:49:59 +0100 Received: from [98.139.52.189] by nm30.bullet.mail.ac4.yahoo.com with NNFMP; 06 Dec 2010 11:49:58 -0000 Received: from [98.139.52.150] by tm2.bullet.mail.ac4.yahoo.com with NNFMP; 06 Dec 2010 11:49:58 -0000 Received: from [127.0.0.1] by omp1033.mail.ac4.yahoo.com with NNFMP; 06 Dec 2010 11:49:58 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 12226.15059.bm@omp1033.mail.ac4.yahoo.com Received: (qmail 89153 invoked by uid 60001); 6 Dec 2010 11:43:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1291635797; bh=sWFnhGiBX7U83VkVIRk1ih79Dn8yWxkX2z82ZOqQe5w=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=helc84jaLIX+tvrb6zIF20kX0UIAqitp+tu9529cigRF4tZ8Hdla5+yUAKTwffLoAtkE4gscW3giADSUjAlBY41Q2FrYXfz1SC76IJWl3WMaVyBNW8Hk4TYTpuwLKkIjZUlkuecOri269TKc+LTh4bAs+8peXnfs+HxRaW7G2EI= DomainKey-Signature:a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=i72HKIEUbvWZw7mMLgLHhHa5H0/10EfQLQhD34N7OEOZaxEGdIyLtxuh2pUTxIA0/ZKTnIwlmX3U1yeL2ejNyOS3krJa4nYF6JYdA9SGss4aaoCNxu6/gPJjaOMrGvzfIuk3P1fXmmZGS6VqlyYBk1rxQLHHM0hWtDfu0JQmfPA=; Message-ID: <926418.88102.qm@web65410.mail.ac4.yahoo.com> X-YMail-OSG: OtezTR0VM1kbyCAihDciegXXxNsbGv80Df7KdT5zFT6ke_T UhBcq9wAZlgiI20HOItsmUUPc6IG07LYtDqFJxMCPCbTT50vhtw8qmCX6mwE q7D0na3KaNPKUJEkDCRr1GZ31TxjVISXGa_DPfpXPWh4E9fSiIQCjQN5aj6z Ku0TJ5LwpNaz9d9jOJji14_CP3OPWKr9xt5qiKmsQNeh1AfG17jRtLLgnjWM 4Uiq.vgB4lzYGMKQ9NJoQzl1fjU1YLRjnTk310yAUL4_B8o6HkWaNZJ1Q3GU D2GUsd106pxxDNSPY81KcqS3IYVGJzYUokFiRmpYUugm4G3KML9Jd_1RHBXs tdneqrA-- Received: from [147.188.192.41] by web65410.mail.ac4.yahoo.com via HTTP; Mon, 06 Dec 2010 03:43:17 PST X-Mailer: YahooMailClassic/11.4.20 YahooMailWebService/0.8.107.285259 Date: Mon, 6 Dec 2010 03:43:17 -0800 (PST) From: zaid khalid Subject: help with regular expression To: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1446877188-1291635797=:88102" X-Spam: no; 0.00; ocaml:01 ocaml:01 syntax:01 regexp:01 syntax:01 regexp:01 aba:98 aba:98 matched:01 matched:01 strings:01 strings:01 expression:02 expression:02 string:02 --0-1446877188-1291635797=:88102 Content-Type: text/plain; charset=us-ascii Hi Folks I want some help in writing regular expressions in Ocaml, as I know how to write it in informal way but in Ocaml syntax I can not. For example I want to write "a* | (aba)* ". Another question if I want the string to be matched against the regular expression to be matched as whole string not as substring what symbol I need to attach to the substring, i.e if I want only concrete strings accepted (like (" ", a , aa , aaa, aba, abaaba), but not ab or not abaa). Hint I am using (Str.regexp) Thanks --0-1446877188-1291635797=:88102 Content-Type: text/html; charset=us-ascii
Hi Folks

I want some help in writing regular expressions in Ocaml, as I know how to write it in informal way but in Ocaml syntax I can not. For example I want to write "a* | (aba)* ".

Another question if I want the string to be matched against the regular expression to be matched as whole string not as substring what symbol I need to attach to the substring, i.e if I want only concrete strings accepted (like (" ", a , aa , aaa, aba, abaaba), but not ab or not abaa).


Hint I am using (Str.regexp)
Thanks


--0-1446877188-1291635797=:88102-- 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 60C69BBAF for ; Mon, 6 Dec 2010 14:11:44 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApAFALJv/ExQW+UMgWdsb2JhbACVIo4UFQEBFiIivHWFSQSKbg X-IronPort-AV: E=Sophos;i="4.59,305,1288566000"; d="scan'208";a="91614749" Received: from lo.gmane.org ([80.91.229.12]) by mail1-smtp-roc.national.inria.fr with ESMTP; 06 Dec 2010 14:11:44 +0100 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PPar1-0000A2-6a for caml-list@inria.fr; Mon, 06 Dec 2010 14:11:43 +0100 Received: from avelizy-155-1-50-177.w86-217.abo.wanadoo.fr ([86.217.25.177]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 06 Dec 2010 14:11:43 +0100 Received: from sylvain by avelizy-155-1-50-177.w86-217.abo.wanadoo.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 06 Dec 2010 14:11:43 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Sylvain Le Gall Subject: Re: help with regular expression Date: Mon, 6 Dec 2010 13:11:29 +0000 (UTC) Message-ID: References: <926418.88102.qm@web65410.mail.ac4.yahoo.com> X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: avelizy-155-1-50-177.w86-217.abo.wanadoo.fr User-Agent: slrn/pre1.0.0-18 (Linux) X-Spam: no; 0.00; le-gall:01 regexp:01 pcre-ocaml:01 syntax:01 regexp:01 syntax:01 eol:01 pcre:01 wrote:01 wrote:01 jambon:01 jambon:01 expression:02 match:02 meaningful:04 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 http://martin.jambon.free.fr/mikmatch-manual.html http://martin.jambon.free.fr/mikmatch.html You can use pcre and str with mikmatch. Regards, Sylvain Le Gall 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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id B6DBEBBAF for ; Mon, 6 Dec 2010 18:31:38 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoIAAKKs/EzUTWUHkWdsb2JhbACDUJ9sFQEBAQEJCwoHEQQerTSQQIEhgzVzBI11 X-IronPort-AV: E=Sophos;i="4.59,306,1288566000"; d="scan'208";a="83211332" Received: from mx3.wp.pl ([212.77.101.7]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 06 Dec 2010 18:31:38 +0100 Received: (wp-smtpd smtp.wp.pl 238 invoked from network); 6 Dec 2010 18:31:34 +0100 Received: from 18-161.2-0.pl (HELO [192.168.1.101]) (d0@[91.189.18.161]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with AES256-SHA encrypted SMTP for ; 6 Dec 2010 18:31:34 +0100 Message-ID: <4CFD1DEF.6070006@wp.pl> Date: Mon, 06 Dec 2010 18:31:27 +0100 From: Dawid Toton User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101027 Thunderbird/3.0.10 MIME-Version: 1.0 To: caml-list Subject: Re: help with regular expression References: <926418.88102.qm@web65410.mail.ac4.yahoo.com> In-Reply-To: <926418.88102.qm@web65410.mail.ac4.yahoo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-WP-AV: skaner antywirusowy poczty Wirtualnej Polski S. A. X-WP-SPAM: NO 0000000 [QdOk] X-Spam: no; 0.00; ocaml:01 ocaml:01 syntax:01 regexp:01 unreadable:01 error-prone:01 regexp:01 syntax:01 trivial:01 mli:01 aba:98 aba:98 wrote:01 dynamically:01 compile:01 On 12/06/2010 12:43 PM, zaid khalid wrote: > I want some help in writing regular expressions in Ocaml, as I know how to write it in informal way but in Ocaml syntax I can not. For example I want to write "a* | (aba)* ". > > Another question if I want the string to be matched against the regular expression to be matched as whole string not as substring what symbol I need to attach to the substring, i.e if I want only concrete strings accepted (like (" ", a , aa , aaa, aba, abaaba), but not ab or not abaa). > I also had problems with Str (regexp descriptions being unreadable, error-prone and hard to generate dynamically) and decided just to stop using Str. I have a tiny module [1] made with clarity in mind. It is pure OCaml. It defines operators like $$ to be used in regexp construction. This way syntax of the expressions is checked at compile time. Also, it is trivial to build them at run time. The whole "engine" is contained in a relatively short function HRegex.subwords_of_subexpressions, so I believe anybody can hack it without much effort. I haven't measured performance of this implementation. I expect it to be slow when processing long strings. It's just OK for my needs so far. Anyway, the important part is the module interface. It expresses my point of view on this topic. The code is available in a mercurial repository [2]. The exemple "a* | (aba)* " would become: open HRegex.Operators let rx = (!* !$ "a") +$ (!* !$ "aba") Dawid [1] http://hg.ocamlcore.org/cgi-bin/hgwebdir.cgi/hlibrary/hlibrary/raw-file/tip/HRegex.mli [2] http://hg.ocamlcore.org/cgi-bin/hgwebdir.cgi/hlibrary/hlibrary 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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id B955FBBAF for ; Tue, 7 Dec 2010 00:36:20 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AowBAC4C/UxiizTmlGdsb2JhbACUdTGOJwEBAQEJCwgJEQMfrn6CGYUbiQQBBAQBhUQEhF+JIg X-IronPort-AV: E=Sophos;i="4.59,307,1288566000"; d="scan'208";a="83224470" Received: from nm8-vm0.bullet.mail.ac4.yahoo.com ([98.139.52.230]) by mail2-smtp-roc.national.inria.fr with SMTP; 07 Dec 2010 00:36:19 +0100 Received: from [98.139.52.196] by nm8.bullet.mail.ac4.yahoo.com with NNFMP; 06 Dec 2010 23:36:18 -0000 Received: from [98.139.52.165] by tm9.bullet.mail.ac4.yahoo.com with NNFMP; 06 Dec 2010 23:36:18 -0000 Received: from [127.0.0.1] by omp1048.mail.ac4.yahoo.com with NNFMP; 06 Dec 2010 23:36:18 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 500697.68376.bm@omp1048.mail.ac4.yahoo.com Received: (qmail 91412 invoked by uid 60001); 6 Dec 2010 23:29:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1291678177; bh=g9h2Z+omqnAqKZRAnJ4iuC+pUh+m+WxjknltRbnebeA=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=V+MUEeYSwmr8adnRqhfolZl0nkfW145/GzwEKrVK5PBLFW/xfqUMyjFuCLOnqD7cf72usL690yUF8xhDsCJJcnrLrN1jeviPuYy++FGpbsjs0LSaR//RoV0B4VSMCOWvKTX1dV8z0tl6dtGeRLwuCcih60m4Ko0UkqKT0HUBvxY= DomainKey-Signature:a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=SJGY7qIwUsayNleYjRhwdl5FQ7JRAK53zVnBzc8t1PoNXXpqviWmppJtnesnNB7nTPiabwYZOT2MylhQiaI1C63x85b/wJ2MJvNcUBvRWVHKuIbCWgJ7tbiauUy54vQcchnhlG/AJlUc3tRmsd/RLRq1HlCrEzHmLPBl7wMqrnE=; Message-ID: <317197.91134.qm@web65412.mail.ac4.yahoo.com> X-YMail-OSG: 0r8xmoQVM1ntX3G7Byr5Q5O7HPWHodyN64BrDUVyEVDIeZA m0qWPzCnA24JIw2CWEHZt5ifjmAnbAZHImL1z6zhlaMOM_xWDZQA6.zh.ych 2NvORinsu_iHxJ6lo.NBko0Pw_5FmdOaaV8uuirFeSFCKudEGVDAV1CI_vi3 A7dtkcgdzSIosNNb5Hp6dp8fdAOsqQYZC_JhRF4tjkVYB6_eeSM7EKmZ9oRE jyap7xrmfRPMI1qGd_WfuigrTKdcWnC2VGf6a0MfZz4CH4rsADQxpCt2p256 sdp8cKtGI9G93iHNOucH__1HzfnjICmkQOzRf5g-- Received: from [94.173.177.99] by web65412.mail.ac4.yahoo.com via HTTP; Mon, 06 Dec 2010 15:29:37 PST X-Mailer: YahooMailClassic/11.4.20 YahooMailWebService/0.8.107.285259 Date: Mon, 6 Dec 2010 15:29:37 -0800 (PST) From: zaid khalid Subject: HELP : with regular expression To: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-2010253898-1291678177=:91134" X-Spam: no; 0.00; regexp:01 pcre-ocaml:01 cheers:01 regexp:01 pcre-ocaml:01 cheers:01 aba:98 abb:98 aba:98 abb:98 define:02 define:02 expression:02 expression:02 match:02 --0-2010253898-1291678177=:91134 Content-Type: text/plain; charset=us-ascii Hi folks Thank you for all your replies. I think I am still struggling to find a solution to my issue using "Str.regexp", and using Pcre-ocaml needs some time to be familiar with as there is no enough examples and discussion on it. Ill put my issue again as if someone can help me to find a solution to it with the "Str" . I want to define regular expression and after that I want to check if particular string is a prefix of the given regular expression. Example: a* | (aba)* so when you test "abaaba" the result will be true (complete match) and when we check "abaa" the result is true as well but when we check "abb" the result is false. I look forward to your suggestions. Cheers, Zaid --0-2010253898-1291678177=:91134 Content-Type: text/html; charset=us-ascii
Hi folks

Thank you for all your replies. I think I am still struggling to find a solution to my issue using "Str.regexp", and using Pcre-ocaml needs some time to be familiar with as there is no enough examples and discussion on it.

Ill put my issue again as if someone can help me to find a solution to it with the "Str" .

I want to define regular expression and after that I want to check if particular string is a prefix of the given regular expression.

Example: a* | (aba)* so when you test "abaaba" the result will be true (complete match) and when we check "abaa" the result is true as well but when we check "abb" the result is false.

I look forward to your suggestions.

Cheers,
Zaid

--0-2010253898-1291678177=:91134-- 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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 125FEBBAF for ; Tue, 7 Dec 2010 16:56:09 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiYBAN7n/UzRVda0kGdsb2JhbACUfYYvAYgMCBUBAQIJCQwHEQQepj+JaoIYhT0uiFYBAQMFhUQEgV6DBIYPhgU X-IronPort-AV: E=Sophos;i="4.59,311,1288566000"; d="scan'208";a="83326407" Received: from mail-iw0-f180.google.com ([209.85.214.180]) by mail2-smtp-roc.national.inria.fr with ESMTP; 07 Dec 2010 16:56:08 +0100 Received: by iwn37 with SMTP id 37so41724iwn.39 for ; Tue, 07 Dec 2010 07:56:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:cc:content-type; bh=/OIB/PvaeLZOZD1pmpRb0sefSAfI4ctg0+QcqzlX3xQ=; b=BAG6lI9qXDn/XuO8Wl66c5aFBoCzQ05rfR777tS2qYh8J2z18dmbavx+ltzo4x0ef8 qjZj6B/NIvyO+h7IujshRv1iSTTjjBDiy8CB+POrvlvMBb9+VwFH4UKZLunUh5vSBn6j shGbRO0SkEFl9vXleFue3PG4dlGVZ1nkV42Bg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=fFkMbtxBCHvLUl7Lh5h9BQO4UzKoTYcRCL9yFrBKuGRzrKM+UTaaUkUJSDXWwrrHDU qT0K6dWnN62xDFiBu79+bKqCBpcF4ZkrgtWXhQSev1383zWWiLEF9JMWAnju76eUAlrV xYQbkLeHqxVBL93qZFzv3NnycL0YQdszI316I= Received: by 10.231.33.74 with SMTP id g10mr939804ibd.117.1291737367311; Tue, 07 Dec 2010 07:56:07 -0800 (PST) MIME-Version: 1.0 Received: by 10.231.11.132 with HTTP; Tue, 7 Dec 2010 07:55:47 -0800 (PST) In-Reply-To: <317197.91134.qm@web65412.mail.ac4.yahoo.com> References: <317197.91134.qm@web65412.mail.ac4.yahoo.com> From: Ashish Agarwal Date: Tue, 7 Dec 2010 10:55:47 -0500 Message-ID: Subject: Re: [Caml-list] HELP : with regular expression To: zaid khalid Cc: caml-list@yquem.inria.fr Content-Type: multipart/alternative; boundary=000325575aa2ebf8180496d40aad X-Spam: no; 0.00; pcre:01 regexp:01 substrings:01 regexp:01 ocaml:01 pcre:01 bool:01 substrings:01 bool:01 pcre-ocaml:01 cheers:01 beginner's:01 ocaml:01 bug:01 pcre-ocaml:01 --000325575aa2ebf8180496d40aad Content-Type: text/plain; charset=ISO-8859-1 I know you're asking for a solution with Str. Since I can't help with that, let me give you the Pcre solution instead. Hopefully my explanations will make up for the lack of examples to help you start using it. pmatch is the function you care about. Ignore most of the arguments. All you need to do is pass the regular expression and the string to match against. The regular expression can be given in either the ~rex or ~pat named arguments (not both). Use ~pat for hacking, and be sure to compile to ~rex if you're doing lots of matches. Notice that almost every function has the same arguments, so once you learn this one the others will make sense too. extract is the second useful function. pmatch just returns true or false if the regexp matches or not. extract will give you all the matching substrings, which is useful to see what your regexp is actually doing (and of course if you need the matched string for later use). After you use these two functions you can start looking at the numerous other ones that let you do more detailed things. The regular expression I came up with for what you want is "(a+|(aba)+)$". Let's test it: $ ocaml Objective Caml version 3.12.0 # #require "pcre";; # open Pcre;; # pmatch ~pat:"(a+|(aba)+)$" "abaaba";; - : bool = true # extract ~pat:"(a+|(aba)+)$" "abaaba";; - : string array = [|"abaaba"; "abaaba"; "aba"|] Note that extract gives as its first result the "full match at index 0" and then all the substrings that match. I'm actually not sure what the use of this is, and I always set full_match to false to avoid the duplication. # pmatch ~pat:"(a+|(aba)+)$" "abaa";; - : bool = true # extract ~full_match:false ~pat:"(a+|(aba)+)$" "abaa";; - : string array = [|"aa"; ""|] # pmatch ~pat:"(a+|(aba)+)$" "abb";; - : bool = false # extract ~full_match:false ~pat:"(a+|(aba)+)$" "abb";; Exception: Not_found. Hope that helps. On Mon, Dec 6, 2010 at 6:29 PM, zaid khalid wrote: > Hi folks > > Thank you for all your replies. I think I am still struggling to find a > solution to my issue using "Str.regexp", and using Pcre-ocaml needs some > time to be familiar with as there is no enough examples and discussion on > it. > > Ill put my issue again as if someone can help me to find a solution to it > with the "Str" . > > I want to define regular expression and after that I want to check if > particular string is a prefix of the given regular expression. > > Example: a* | (aba)* so when you test "abaaba" the result will be true > (complete match) and when we check "abaa" the result is true as well but > when we check "abb" the result is false. > > I look forward to your suggestions. > > Cheers, > Zaid > > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > --000325575aa2ebf8180496d40aad Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I know you're asking for a solution with Str. Since I can't help wi= th that, let me give you the Pcre solution instead. Hopefully my explanatio= ns will make up for the lack of examples to help you start using it.

pmatch is the function you care about. Ignore most of the ar= guments. All you need to do is pass the regular expression and the string t= o match against. The regular expression can be given in either the ~rex or = ~pat named arguments (not both). Use ~pat for hacking, and be sure to compi= le to ~rex if you're doing lots of matches.=A0Notice that almost every = function has the same arguments, so once you learn this one the others will= make sense too.

extract is the second useful function. pmatch just retu= rns true or false if the regexp matches or not. extract will give you all t= he matching substrings, which is useful to see what your regexp is actually= doing (and of course if you need the matched string for later use).

After you use these two functions you can start looking= at the numerous other ones that let you do more detailed things.

The regular expression I came up with for what you want is = "(a+|(aba)+)$". Let's test it:

$ ocaml
=A0=A0 =A0 =A0 =A0Objective Caml= version 3.12.0

# #require "pcre";;=
# open Pcre;;

# pmatch ~pat:= "(a+|(aba)+)$" "abaaba";;
- : bool =3D true

# extract ~pat:"(a+|(a= ba)+)$" "abaaba";;
- : string array =3D [|"ab= aaba"; "abaaba"; "aba"|]

Note that extract gives as its first result the "full match at in= dex 0" and then all the substrings that match. I'm actually not su= re what the use of this is, and I always set full_match to false to avoid t= he duplication.

# pmatch ~pat:"(a+|(aba)+)$" "abaa&= quot;;; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0
- : bool =3D true<= /div>

# extract ~full_match:false ~pat:"= (a+|(aba)+)$" "abaa";;
- : string array =3D [|"aa"; ""|]
=
# pmatch ~pat:"(a+|(aba)+)$" "abb";;
- : bool =3D false

# extract ~full_mat= ch:false ~pat:"(a+|(aba)+)$" "abb";;=A0
Exception: Not_found.

Hope that helps.<= /div>


On Mon, Dec 6, 2010 at 6= :29 PM, zaid khalid <zaidbenaz@yahoo.com> wrote:
Hi folks =

Thank you for all your replies. I think I am still struggling to fi= nd a solution to my issue using "Str.regexp", and using Pcre-ocam= l needs some time to be familiar with as there is no enough examples and di= scussion on it.

Ill put my issue again as if someone can help me to find a solution to = it with the "Str" .

I want to define regular expression an= d after that I want to check if particular string is a prefix of the given = regular expression.

Example: a* | (aba)* so when you test "abaaba" the result wil= l be true (complete match) and when we check "abaa" the result is= true as well but when we check "abb" the result is false.

I look forward to your suggestions.

Cheers,
Zaid


_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.in= ria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--000325575aa2ebf8180496d40aad--