(?x-ims: # group, but do not capture (disregarding # whitespace and comments) (case-sensitive) # (with ^ and $ matching normally) (with . not # matching \n): ^ # the beginning of the string ( # group and capture to \1: ( # group and capture to \2: \^ # '^' [%A-Za-z\d]+ # any character of: '%', 'A' to 'Z', 'a' # to 'z', digits (0-9) (1 or more times # (matching the most amount possible)) ) # end of \2 ( # group and capture to \3: $ # before an optional \n, and the end of # the string | # OR = # '=' | # OR \( # '(' bunch_of_ugly_su # 'bunch_of_ugly_subscripts' bscripts # \) # ')' ) # end of \3 ) # end of \1 ) # end of grouping