Build a named capture group (X being the pattern you want to capture):
X
(?'name'X) (?X) (?PX)
Reference a named capture group:
${name} \{name} g\{name}
Python and Java don't allow multiple groups to use the same name.