我有一个类似这样的html:
<script>
$(“table:first”).after(“<a href=\“https://example.com/test123/\”
style=\“display: block; margin-left: auto; margin-right: auto; margin-
bottom: 116px;\“><img
src=\“https://example.com/images/banners/image.png\” alt=\“Example\”
width=\“88px\” style=\“display: block; margin-left: auto; margin-right: auto; \“></a>“);
</script>
<img src="https://example.com/images/banners/image1.png" alt="image">
我需要用url搜索所有img标签:
https://example.com/images/banners/image1.png
和https://example.com/images/banners/image.png
。仅当我匹配这些网址之一时,我才需要返回true。我该怎么办?我的模式:
`<img.+?src=[\"']((?:https://example.com/images/banners/image1.png?|www).*)[\"'].*?>`
但是我得到了错误:
https://regexr.com/4capb
答案 0 :(得分:0)
您需要转义固线(/)字符,这在正则表达式中具有特殊含义。
所以:
<img.+?src=[\"']((?:https:\/\/example.com\/images\/banners\/image1.png?|www).*)[\"'].*?>