Given this string:
text = "hello world pattern 24 4 5 this is an example pattern 4 3 11 "
I need to substitute "pattern X Y Z" with "patternX-Y-Z", where X, Y, Z are numbers (no space between "pattern" and the first number). So far, I'm doing this through this regex :
text= re.sub('pattern\s(\d+)\s(\d+)\s(\d+)', r'pattern\1-\2-\3', text).strip()
Suppose I have more than three groups (something like "pattern 12 3 5 7 5 and pattern 34 5 4") where the number of groups is not fixed and it is unknown a priori, how could I write my regex? Is there a way for writing a recursive regex for substitution?