import re
text = "§s 23, 12"
print(re.sub(r'§\w*\s+\d+(?:,\s*\d+)*', lambda x: re.sub(r'\s+', '_', x.group()), text))