I\'m pretty new to Python, but we are working on cleaning up some text files, and, among others, I will need to do the following: Replace spaces with underscores, but only in so
Use re.sub with a lambda:
re.sub
x = re.sub(r'/2.*?/1', lambda x: re.sub(r'\s+', '_', x.group()), x)
Match all strings between /2 and /1 and replace whitespace strings only there with the nested re.sub.
/2
/1