Nice!
Can you use something like this (and perhaps clarify in the docstring that we're trying to grab the `_r<int>` at the end)?
```python
rg = re.compile('mc12\_8TeV\.(?P<dsid>\d+)\..*NTUP.*\_r(?P<recotag>\d+)_.*')
match = rg.search(dsname)
if match:
    print match.group('recotag')
```