caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <markus@oefai.at>
To: onlyclimb <onlyclimb@163.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] pcre
Date: Sun, 8 Dec 2002 14:51:55 +0100	[thread overview]
Message-ID: <20021208135155.GA20297@fichte.ai.univie.ac.at> (raw)
In-Reply-To: <3DF3B807.9080502@163.com> <3DF3B51F.7060704@163.com>

On Sun, 08 Dec 2002, onlyclimb wrote:
> let s ="abcdbcd" ;;
> let t  = pcre_exec ~pat:"bc"  s ;;
> 
> t = [| 1; 3; 0 |]
> 
> what does the last zero mean?

The matching engine needs extra workspace. This wasn't mentioned in the
documentation (added now). You'll rarely need this function anyway. Better
use "exec", "exec_all" or "extract", "extract_all" for your purposes.

On Sun, 08 Dec 2002, onlyclimb wrote:
> Dose the int array returned by pcre_exec contain the offsets of all
> the matches or the first match from pos?

It contains the offsets of the first, whole match followed by the
offsets of matched subpatterns (introduced with parentheses in the
pattern string).

> However as i tried, it seems that it returned the first match offects,
> then why it return a int array  not a turple of int*int which refers to 
> (from, to) ?

Because there can be arbitrarily many subpatterns. E.g. try this:

  let t = pcre_exec ~pat:"a(bc)"  s ;;

  t = [|0; 3; 1; 3; 0; 0|]

The whole match ranges from character 0 to 3 (exclusive), the first
subgroup from 1 to 3. The remaining zeroes belong to the extra workspace.

Using "extract" will make things clearer. Then the result is:

  [|"abc"; "bc"|]

With "exec" you can extract strings of matched (sub)patterns more
efficiently if you do not want to access all of them.

Regards,
Markus Mottl


-- 
Markus Mottl                                             markus@oefai.at
Austrian Research Institute
for Artificial Intelligence                  http://www.oefai.at/~markus
-------------------
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


  reply	other threads:[~2002-12-08 13:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-08 21:22 [Caml-list] another question about pcre_exec onlyclimb
2002-12-08 21:09 ` [Caml-list] pcre onlyclimb
2002-12-08 13:51   ` Markus Mottl [this message]
2002-12-29 15:42 [Caml-list] PCRE Oleg
2002-12-29 18:41 ` Markus Mottl

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=20021208135155.GA20297@fichte.ai.univie.ac.at \
    --to=markus@oefai.at \
    --cc=caml-list@inria.fr \
    --cc=onlyclimb@163.com \
    /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).