简体   繁体   English

使用正则表达式从文本中提取图像 url

[英]Extract image urls using regex from a text

I'm trying to extract all image urls from a html text that contains a specific word.我正在尝试从包含特定单词的 html 文本中提取所有图像 url。 I tried the following regex but it fails on some string that doesn't have spaces in it.我尝试了以下正则表达式,但它在一些没有空格的字符串上失败。

Regex正则表达式

(http\S+logo\S+[.]png|http\S+logo\S+[.]jpg|http\S+logo\S+[.]svg|http\S+logo\S+[.]jpeg)

Text文本

https://a0.muscache.com/airbnb/static/logos/trips-og-1280x630-9de9c338cc3fd9b5663fb80be0cbe8c2.jpg
https://a0.muscache.com/airbnb/static/logos/trips-og-1280x630-9de9c338cc3fd9b5663fb80be0cbe8c2.png
https://a0.muscache.com/airbnb/static/logos/trips-og-1280x630-9de9c338cc3fd9b5663fb80be0cbe8c2.svg
https://media.glassdoor.com/sqls/575263/uber-squarelogo-1537216184790.png","logo2x":"https://media.glassdoor.com/sqlm/575263/uber-squarelogo-1537216184790.png
"https://media.glassdoor.com/sqls/575263/uber-squarelogo-1537216184790.png","logo2x":"https://media.glassdoor.com/sqlm/575263/uber-squarelogo-1537216184790.png"

Can anyone ecplain how to extract image urls from above?任何人都可以说明如何从上面提取图像网址吗?

If you want to extract the entire URL, perhaps, simply:如果您想提取整个 URL,也许,只需:

https:.*?\.(?:png|jpg|svg)

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

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