Re: [pcre-dev] Capturing groups

Pàgina inicial
Delete this message
Autor: Philip Hazel
Data:  
A: norulez
CC: PCRE Mailing Lists
Assumpte: Re: [pcre-dev] Capturing groups
On Mon, 20 Feb 2012, norulez@??? wrote:

> I'm new to PCRE, so please forgive me if i ask an already answered question.
>
> I saw function definitions for up to 10 arguments for capture groups, i also noticed that i have to add a predefined datatype for the capture groups.


Which function is that? There is no limit of 10 anywhere in the PCRE
library. Are you calling PCRE from some other environment?

> 1.) Is there a way to use a vector/list instead of individual arguments where the vector/list getting filled with founded captures?


Yes. That is exactly the C interface to PCRE. The pcre_exec() function
has this API:

int pcre_exec(const pcre *, const pcre_extra *, const char *, int, int,
int, int *, int);

The final two arguments are a pointer to a vector of ints and the number
of slots in the vector. They are used in pairs to return captured
groups. See the pcreapi documentation for details.

> 2.) What if I need more than 10 capture groups?


There is no limit at the C library level. (Well, there is, but it is 64K
or thereabouts.)

> 3.) Is it possible to always use strings as arguments (if the expression is for example (\d{2, 4}))?


Sorry. I don't understand this question. Please give more details. (The
argument to pcre_compile() is a zero-terminated string; the argument to
pcre_exec() is a string and a length - so that it can contain characters
whose codepoint is zero).

Philip

--
Philip Hazel