You’d need something like a match list/map/dictionary that you can access. Go seems to have the required functionality, but it is apparently not exposed in Hugo.
There’s an example on how to work with capturing groups here:
That’s clumsy (to use a friendly term). A more complete support for REs in Hugo would probably be nice.