I struggle with separating a given string foobar123 between a word and a digit of unknown length with an underscore (Result: foobar_123). I've tried to use regex to find the match r1 (works). But after this, I have no idea, how to separate the corresponding match.
import re
x = "foobar123"
y = re.sub("[a-z]{1}\d{1}", "\1", x)
print(y) # Output: "fooba23"
I think it should be done with "\1" to access the previous match. So I've tried to replace the found match with itself, but this results in: fooba23. Shouldn't it be foobar123.
Thanks in advance.
UPDATE:
Sorry for the typo in the code above, it should be [a-z] not [0-9].