PCRE: DEFINE statement for lookarounds

Viewed 356

Stepping deeper into the world of regular expressions, I came across the DEFINE Statement in PCRE.
I have the following code (which defines a lowercase, an uppercase and anA group (I know it's rather useless at this point, thanks :):

(?(DEFINE)
 (?<lowercase>(?=[^a-z]*[a-z])) # lowercase
 (?<uppercase>(?=[^A-Z]*[A-Z])) # uppercase
 (?<anA>A(?=B))
)
^(?&anA)

Now, I wonder how I can combine the lookahead (lowercase in this example) with the anA part? Admittedly, struggled to find an appropriate documentation on the DEFINE Syntax. Here's a regex101.com fiddle.
To make it somewhat clearer, I'd like to have the opportunity to combine subroutines. For instance, with the above example (to i.e. validate a password which needs to have an A followed by B and some lowercase letters), I could do the following:

^(?=[^a-z]*[a-z]).*?A(?=B).*

How can this be done with the above subroutines?

EDIT: For reference, I ended up using the following construct:

(?(DEFINE)
 (?<lc>(?=[^a-z\n]*[a-z]))      # lowercase
 (?<uc>(?=[^A-Z\n]*[A-Z]))      # uppercase
 (?<digit>(?=[^\d\n]*\d))       # digit
 (?<special>(?=.*[!@]+))        # special character
)
^(?&lc)(?&uc)(?&digit)(?&special).{6,}$
1 Answers
Related