First of all thank you for taking the time to look into this.
Second, apologies for not providing more engine details. I should have known better.
I am using PCRE as you guessed and I am indeed looking for the underlined part in aaap1bbbp1cccp2ddd (I need p1 and p2 separated but that's easy).
I tried your pattern on a simple string and altho I don't understand how it works it does seem to work.(I will study it)
FYI p1 is (?<p1>type=\d+, shape=((\d+[ ,])+))
and p2 is (?<p2>≡⍴2 0⍕B *\d+ (\d+)) (some Unicode chars in there)
The UTF8 text to search includes \n and DOTALL has to be used.
From your pattern and mine above I created the pattern
((?<p1>type=\d+, shape=(?:(?:\d+[ ,])+)))(?:(?!(?&p1)|(?<p2>≡⍴2 0⍕B *\d+ (\d+))).)*((?&p2))
which defines p1 and p2 to be reused and that worked!
Thanks a lot!