Formatting regex search for pybids filters for conditional return

My data (bids-formatted) has multiple T1w images for each session, and not every session will have all of the possible T1w images. Possible acquisition values that distinguish the T1s are: 800um, 800umxND, MPRAGE1mm. I’m trying to format the right regex query for the layout.get() function to return 800um if that acquisition value exists, and MPRAGE1mm if it doesn’t.

This command:
layout.get(suffix = “T1w”, acquisition = “800um$|MPRAGE1mm”, extension=‘nii.gz’, regex_search = True, return_type=“filename”)
will return both the 800um and MPRAGE1mm acquisitions, instead of the behavior I want, only returning the first match to “800um$”.

How do I format the regex to match the behavior I want? I’ve tried acquisition argument values with capture groups like these but haven’t gotten the result I wanted:
(800um$)?(?(1)800um$|MPRAGE1mm) : returns just MPRAGE1mm
(800um$)?(?(1)|MPRAGE1mm): returns both 800um and MPRAGE1mm

I am running a very old version of pybids, 0.12.2, I’m fighting with my environment about updating it now, but wanted to check if this issue will be solvable in any version of pybids.

I think this will work for acquisition: r"^(800um|800umxND|MPRAGE1mm)$"

I think it just needs the parentheses to make the match to end of string separate from the logical or

Thanks for the suggestion, Phil. That regex string still returns all of the files, instead of just returning the first match like I want.
I wonder if pybids regex implementation is set to always use global/return all results?

Oh right, yes layout.get applies the regex to each file name, so it will return all matching files, even if they match different parts of the regex