例如,有谁知道如何用“\r\n<\d+”替换所有出现的“<\d+”正则表达式
"<20"
应该转化为
"\r\n<20"
但是
"> HELLO < asassdsa"
应该保持不变
最佳答案
>>> import re
>>> str = "<20"
>>> output = re.sub(r'<(?=\d)', r'\r\n<', str)
>>> output
'\r\n<20'
关于Python 使用正则表达式替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9192416/