简体   繁体   English

如何使用正则表达式获取这些图像alt标签url

[英]How to get these images alt tag url with regex

I have a bunch of HTML code which contain these images: 我有一堆包含这些图像的HTML代码:

<img alt=\"http://www.adsf1.net/static/1231.jpg\" width=\"100%\">
<img alt=\"http://www.1322.com/files/150818g58.jpg\" width=\"100%\">
<img alt=\"http://www.aerwef.org/sda/sdfawe.jpg\" width=\"100%\">

I manage to match these images with this regex 我设法将这些图像与此正则表达式匹配

<img[^>]+\s*\/?>

But, I would like to get the url from the alt tag using JS, and store it into an array. 但是,我想使用JS从alt标记中获取网址,并将其存储到数组中。

I would like to get a JS array like this (based on the above example) 我想得到一个像这样的JS数组(基于上面的示例)

["http://www.adsf1.net/static/1231.jpg", "http://www.1322.com/files/150818g58.jpg", "http://www.aerwef.org/sda/sdfawe.jpg"]

You can try this regex : 您可以尝试以下正则表达式:

<img alt=\\"(http[^"]*)\\".*

Hope this helps. 希望这可以帮助。

link : https://regex101.com/r/mI3hV1/1 链接: https : //regex101.com/r/mI3hV1/1

Thank you @pawan bhardwaj for the tips and clue. 谢谢@pawan bhardwaj的提示和提示。 I have modified his code for a better match. 我已经修改了他的代码以更好地匹配。

<img.*?alt=\\"(http[^"]*)\\".*?>

For others who are looking for something similar, hope this helps. 对于正在寻找类似内容的其他人,希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM