views:

24

answers:

3

Hi All,

I have a huge string of multiple URLs in javascript which is of the following format:

var urls = "http://..... , http://..... , http://......"

I need to extract all URLs from the string into individual variables of part of an array. I cant do a urls.split(",") as some urls seem to have commas in them.Is there a good regex I can use to solve this problem ?

A: 

Do you know for a fact that the URLs are separated by " , "? If so, split on that!

zigdon
As i told you, URLs can within them have commas.. So split(",") doesnt work.. :(
paypalcomp
@paypal - @zigdon said split(" , "). I.e. there are spaces around the comma. Can your URLs contain commas with spaces around them? If not, his answer works. If so, try @Paul's solution, if all the URLs are absolute and use the http scheme (not https).
LarsH
+1  A: 

Split on a larger string: ", http://" — that avoids the problem of commas in the middle of URLs.

Paul Schreiber
A: 

cool.. got it.. thank you all.. :)

paypalcomp