Author: Philip Hazel Date: To: 760 CC: pcre-dev Subject: Re: [pcre-dev] [Bug 760] Named patterns with same index conflict
On Sun, 14 Sep 2008, Stan Vassilev wrote:
> I think firbiddig it may have some disruptive effects, as apart from the
> name1/name2 collision, there also exists the no_name/name collision,
Oh, indeed. *If* that line is taken, I think you have to insist that all
groups with names have the same names for the same numbers. Or, of
course, just document what happens now.
> What I use switch blocks (?|..|..) for right now, was to merge
> multiple regexes into a single one, while preserving the subpattern
> numbers in each (necessary as I may have backreferences etc. which are
> absolute).
Sounds reasonable. (Of course, with relative backreferences you wouldn't
need this - but I expect your regexes already exist.)
> This works well, but at some point I had the need to see which segment
> exactly matched in the group, so I went and used an empty named
> pattern in the end (as not to abrupt the pattern numbers), as a marker
> of a sort, and checked the name:
Oh my goodness, OK, I can see that is perhaps a plausible thing.
> A workaround I'm experimenting with is to prepend the markers with enough
> '()'-s so that the marker of each segment has a unique index in the entire
> pattern, then I can check the last named pattern name reported and that's my
> marker.
Good Luck! I don't know when I will look at this, but I do know that
making it "work" would require a lot of changes, since PCRE just keeps
the number in the compiled code, so all it knows is that "group 3
matched", for example. There is currently no way to know *which* group 3
if there are several of them.