I am trying to find strings of pattern (letters)(digits) and make them as (letters)-(digits). For e.g.: If test001 is found, replace that with test-001. So, I need to split the string at first digit following the letters. I am using regular expressions 'match' and 'split' functions for the same.
if re.match(r'^\D+\d*$', str):
parts = re.split(r'(?=\d)', str, 1)
updated_str = parts[0] + "-" + parts[1]
It is working for other python versions, but failing for python 3.6 version, throwing error: ValueError: split() requires a non-empty pattern match. Can someone help me with achieving the same, which can work with all the versions of python.