我需要你帮我学正则表达式
https://regex101.com/r/r3pTh0/2
我可以使用以下正则表达式,但仍然需要帮助:
\<\%= image_tag image_url\(\“(.+?)\”\)|\“(.+?)\” %>
替换为:
<img src="\1" alt="\2">
python代码:
originalData = re.sub('<%= image_tag image_url("(.+?)")+, :alt => "(.+?)\" %>', r'<img src="\1" alt="\2">', originalData, flags=re.MULTILINE)
但它似乎并没有取代任何东西
有一个字符串:
<%= image_tag image_url(“/blog/assets/images/2018-11-15/dribbble-developer-interview-jeffrey-chupp.png”), :alt => “Developer interview with Jeffrey Chupp, Director of Engineering at Dribbble” %>
将其替换为html img标记:
<img src="/blog/assets/images/2018-11-15/dribbble-developer-interview-jeffrey-chupp.png" alt="Developer interview with Jeffrey Chupp, Director of Engineering at Dribbble">
您遇到此错误是因为您在regex101.com上选择了PHP风格的regex
只需切换到Python风格,网站就会为您修复正则表达式。命令应为:
至于向映像src添加域前缀,只需在第二个regex过程中将
src="
替换为src="https://somesite.com
或者您可以在替换字符串前面添加域,如下
'<img src="https://somesite.com\1" alt="https://somesite.com\2">'
相关问题 更多 >
编程相关推荐