Python替换使用正则表达式

mno*_*tka 5 python regex

有没有人知道如何用'\ r \n <\ d +'替换'<\ d +'正则表达式的所有ocurence,例如

"<20"
Run Code Online (Sandbox Code Playgroud)

应该转变为

"\r\n<20"
Run Code Online (Sandbox Code Playgroud)

"> HELLO < asassdsa"
Run Code Online (Sandbox Code Playgroud)

shuld不受影响

cod*_*ict 9

>>> import re
>>> str = "<20"
>>> output = re.sub(r'<(?=\d)', r'\r\n<', str)
>>> output
'\r\n<20'
Run Code Online (Sandbox Code Playgroud)