Given a regular expression with named captures, is it possible to determine which named captures are present in the re?
Note: I only have the regular expression – I don’t have a string which matches the re. I want to know if there is a way to look into the structure of the re and find all of the named captures used in the re.
That’s not possible in the general case, because someone could have a
(??{....})code insert that turns into something that uses a named capture of a hitherto unseen name during match execution time.In a specific case you might be able to dig into the underlying structure from the C API.
Devel::Peeksuggests some places you might want to poke around:For example,
PAREN_NAMESlooks promising.But that seems like a lot of work. What do you want to do this for?