Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用正则表达式替换Python_Python_Regex - Fatal编程技术网

使用正则表达式替换Python

使用正则表达式替换Python,python,regex,Python,Regex,有人知道如何替换“import re”的所有文档吗 def更换(值): 返回re.sub(r'(>>导入re >>>str=“为什么不把整个正则表达式放在前面看呢?@Tim:我就是这么想的。也许我们不应该鼓励使用str作为变量名,尽管我总是找不到更好的名称:( "<20" "\r\n<20" "> HELLO < asassdsa" import re def replace(value): return re.sub(r'(<\d)', r'\r\n\1

有人知道如何替换“
import re”的所有文档吗
def更换(值):
返回re.sub(r'(
>>导入re

>>>str=“为什么不把整个正则表达式放在前面看呢?@Tim:我就是这么想的。也许我们不应该鼓励使用
str
作为变量名,尽管我总是找不到更好的名称:(
"<20"
"\r\n<20"
"> HELLO < asassdsa"
import re
def replace(value):
  return re.sub(r'(<\d)', r'\r\n\1', value)
import re
def replace(value):
  return re.sub(r'(?=<\d)', r'\r\n', value)
>>> import re
>>> str = "<20"
>>> output = re.sub(r'<(?=\d)', r'\r\n<', str)
>>> output
'\r\n<20'