简体   繁体   中英

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. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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