Python 正则表达式删除
我有一个正则表达式:Python 正则表达式删除,python,html,regex,cdata,Python,Html,Regex,Cdata,我有一个正则表达式: </title>[\s]*<description[^>]*>(.*?)<img 其中包含以下字符串: 如何编辑此正则表达式以同时删除正则表达式是一个非常强大的工具。这包括将错误引入代码的高风险,特别是当您不知道如何准确处理它们时,这里似乎就是这种情况 您应该始终首先使用Python的内置字符串类,并且仅在必要时使用正则表达式 如果您有字符串my_str,则以下代码将替换my_str中的子字符串: str.replace在这种情况下搜索
</title>[\s]*<description[^>]*>(.*?)<img
其中包含以下字符串:
如何编辑此正则表达式以同时删除正则表达式是一个非常强大的工具。这包括将错误引入代码的高风险,特别是当您不知道如何准确处理它们时,这里似乎就是这种情况 您应该始终首先使用Python的内置字符串类,并且仅在必要时使用正则表达式 如果您有字符串my_str,则以下代码将替换my_str中的子字符串: str.replace在这种情况下搜索lo并将其替换为nothing,从而删除它。当然,您可以根据需要更改此值 看一看
<title>Insane price of last Ford Falcon V8s</title>
<description><![CDATA[FORD dealers are charging a staggering $30,000 more than the recommended retail price — up from $60,000 to $90,000 — for the final Falcon V8 sedans as buyers try to secure a future classic.<img alt="" border="0" src="https://pixel.wp.com/b.gif?host=www.couriermail.com.au&blog=87782261&post=1205849&subd=couriermailatnewscorpau&ref=&feed=1" width="1" height="1" />]]></description>
my_str = "hello world"
my_str.replace("lo", "")
>>> "hel world"