javascript - Matching urls without specific delimiters -


i'm trying match urls inside arbitrary text, no specific delimiters, , multiple items in same line:

http://www.site.com/image1.jpg "http://www.site.com/image2.jpg" 'http://www.site.com/image1.jpg&a=1' 

please not space after fist url, , terminating &a=1

this actual regex: (https?:\/\/.*\.(?:png|jpg)), matches correctly last url, fist , second matched 1 result.

the expected result should instead this:

http://www.site.com/image1.jpg http://www.site.com/image2.jpg http://www.site.com/image1.jpg 

thanks.

if ending .jpg it's easy achieve regexp: /[a-za-z0-9:\/\.-]+\.jpg/. i've added few more url examples test match. result array of matches.

var str = "http://www.site.com/image1.jpg \"http://www.site.com/image2.jpg\" 'http://www.site.com/image1.jpg&a=1' http://www.21d1dk1kk1.org/image.jpg http://www.21d1dk1-kk1.org/image.jpg";  var matches = str.match(/[a-za-z0-9:\/\.-]+\.jpg/g);  

if need match more jpg can use (jpg|gif|png) etc. in place of jpg (eg. [a-za-z0-9:\/\.-]+\.(jpg|gif|png)/g)

having array of matches can output whatever way want iterating it. assume know how deal that.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -