我正在尝试替换长字符串中的几个URL
这里有一个例子:
s = 'https://www.yellowpages.ca/bus/Alberta/Edmonton/MNS-Enterprise-\nLtd/8114324.html, https://411.ca/business/profile/13300641'
由于url中的换行符,匹配将始终在\n
处停止。
我试过了
re.sub(r'(https?://[\S]*)', 'website__', s, re.DOTALL)
但是结果在\n
处中断
'website__\nLtd/8114324.html, website__'
您可以添加
\n
并使用见regex demo详细信息:
https?://
-http://
或https://
[\n\S]+
-一个或多个换行符或非空白字符\b
-直到最右边的单词边界李>见Python demo:
相关问题 更多 >
编程相关推荐