Regex只在不同的URL中查找特定的URL
什么正则表达式只与“myurl.com”中的图像src匹配 我越靠近这个: 现场测试: 正则表达式:Regex只在不同的URL中查找特定的URL,regex,Regex,什么正则表达式只与“myurl.com”中的图像src匹配 我越靠近这个: 现场测试: 正则表达式: <img.+?src=[\"'](.+?)[\"'].*?> 代码示例: <html> ... <br> </b><br> <a href="http://example.com/a/53e39f6582954.html" target="_blank"><img src="http://myurl.com/a/
<img.+?src=[\"'](.+?)[\"'].*?>
代码示例:
<html>
...
<br>
</b><br>
<a href="http://example.com/a/53e39f6582954.html" target="_blank"><img src="http://myurl.com/a/b/c/53e39f658291a.jpg" alt="" border="0"></a>
<a href="http://example.com/a/53e39f660a74d.html" target="_blank"><img src="http://myurl.com/a/b/c/53e39f660a716.jpg" alt="" border="0"></a>
<a href="http://example.com/a/53e39f66a1cdd.html" target="_blank"><img src="http://others.net/a/b/c/53e39f66a1ca6.jpg" alt="" border="0"></a>
<a href="http://example.com/a/53e39f67265ee.html" target="_blank"><img src="http://others.com/a/b/c/53e39f67265b3.jpg" alt="" border="0"></a>
<a href="http://example.com/a/53e39f67ad28f.html" target="_blank"><img src="http://myurl.com/a/b/c/53e39f67ad255.jpg" alt="" border="0"></a>
<a href="http://example.com/a/53e39f6838b67.html" target="_blank"><img src="http://myurl.com/a/b/c/53e39f6838b2b.jpg" alt="" border="0"></a>
<a href="http://example.com/a/53e39f68c564f.html" target="_blank"><img src="http://others.com/a/b/c/53e39f68c5618.jpg" alt="" border="0"></a>
<a href="http://example.com/a/53e39f69630bc.html" target="_blank"><img src="http://myurl.com/a/b/c/53e39f6963085.jpg" alt="" border="0"> ... ...
...
</html>
...
... ...
...
您几乎做到了:
<img[^>]+?src\s*=\s*[\"'](http:\/\/myurl\.com.+?)[\"'].*?>
不过,这一个会更好一些:
<img[^>]+?src\s*=\s*([\"'])(http:\/\/myurl\.com.+?)\1.*?>
它确保引号匹配,但与
$2
中的url匹配您使用的是什么语言?Javascript?