ورود

View Full Version : پیدا کردن کلیه URL های داخل یک String



nasr
چهارشنبه 14 آبان 1393, 15:26 عصر
سلام
من یک متنی دارم شبیه به این

line-height: 22px; font-size: 12px; background-color: rgb(234, 234, 234);"> border-image: none; height: 25px; line-height: 22px; font-size: 12px; background-color: rgb(234, 234, 234);"><span style="margin: 0px; padding: 0px;"><img alt="" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; vertical-align: middle;" src="http://94.182.138.34/test/Image/Icon/no.png"><span style="margin: 0px; padding: 0px;"><img alt="" style="margin: 0px; padding: 0px; border: 0px currentColor; border-image: none; vertical-align: middle;" src="http://94.182.138.34/test/Image/Icon/yes.png "></img></span></td> </tr>
الان نیاز دارم که از داخل این متن بگه که دوتا URL وجود داره
1- http://94.182.138.34/test/Image/Icon/no.png (http://94.182.168.34/Digikala/Image/Icon/no.png)
2- http://94.182.138.34/test/Image/Icon/Yes.png (http://94.182.168.34/Digikala/Image/Icon/Yes.png)

یعنی میخوام URL های داخل یک متن را جدا کنم و یه URL دیگه جایگزینش کنم

ممنون میشم کسی راهنمایی کنه

uthman
چهارشنبه 14 آبان 1393, 18:21 عصر
سلام. از این Regex استفاده کن:


(https?):\/\/(www\.)?[a-z0-9\.:].*?(?=\s)

nasr
چهارشنبه 14 آبان 1393, 19:22 عصر
تشر

این جواب داد

http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?