I have a pattern that I want to use in a couple of places, but I want access to an inner part of the pattern. Is there a way to do this?
In this simplified
It is not possible, as the capture groups inside a DEFINE
block are only "visible" inside that block and cannot be accessed from the pattern.
See this perlre reference:
This allows one to define subpatterns which will be executed only by the recursion mechanism... Note that capture groups matched inside of recursion are not accessible after the recursion returns, so the extra layer of capturing groups is necessary. ... Finally, keep in mind that subpatterns created inside a
DEFINE
block count towards the absolute and relative number of captures.
So, even though you have 3 named capture groups, you can only access test
group that was defined in the main pattern.