I have a two strings
/some/path/to/sequence2.1001.tif
and
/some/path/to/sequence_another_u1_v2.tif
I want to write a function so that both strings can be split up into a list by some regex and joined back together, without losing any characters.
so
def split_by_group(path, re_compile):
# ...
return ['the', 'parts', 'here']
split_by_group('/some/path/to/sequence2.1001.tif', re.compile(r'(\.(\d+)\.')
# Result: ['/some/path/to/sequence2.', '1001', '.tif']
split_by_group('/some/path/to/sequence_another_u1_v2.tif', re.compile(r'_[uv](\d+)')
# Result: ['/some/path/to/sequence_another_u', '1', '_v', '2', '.tif']
It's less important that the regex be exactly what I wrote above (but ideally, I'd like the accepted answer to use both). My only criteria are that the split string must be combinable without losing any digits and that each of the groups split in the way that I showed above (where the split occurs right at the start/end of the capture group and not the full string.
I made something with finditer but it's horribly hacky and I'm looking for a cleaner way. Can anyone help me out?