【发布时间】:2015-03-27 12:10:45
【问题描述】:
我想替换像
这样的字符串'''1 2 3 4 5 6 abcde fghij klmno pqrst 7 8 9 10 uvwxyz abcdef 11 12 13'''
到
'''1 2 3 4 5 6
abcde fghij klmno pqrst
7 8 9 10
uvwxyz abcdef
11 12 13'''
这是我的方法:
s = re.sub(r'(\d) ([a-z])', r'\1\n\2', s)
s = re.sub(r'([a-z]) (\d)', r'\1\n\2', s)
如何在one regular expression 中做到这一点?我知道我可以使用re.findall 和groups 来做到这一点,但我想找到更简单的方法?
【问题讨论】: