Author: Philip Hazel Date: To: Ashley Thomas CC: pcre-dev Subject: Re: [pcre-dev] PCRE Question
On Wed, 23 Jan 2008, Ashley Thomas wrote:
> I have a question regarding PCRE.
>
> If multiple patterns (say 100 patterns) are compiled using pcre_compile()
> and then later on, a pcre search is done on an input string which
> results in a match,
> is it possible to know which pattern (among the 100) was matched?
I am afraid you have not given enough information for your question to
be answered, or you have misunderstood how PCRE works. A call to
pcre_compile() compiles one pattern. You would have to call it 100 times
to compile 100 patterns. Matching is done by calling pcre_exec() or
pcre_dfs_exec(), in each case, giving it one compiled pattern. So of
course the program knows which one matched.
Perhaps you are thinking of compiling one large pattern with 100
alternatives? Something like A|B|C|D|... ? In that case, no, you cannot
tell which alternative matched, unless you make use of PCRE's callout
feature and stick a callout at the end of each alternative.