0

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 ?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

2 Comments

As i told you, URLs can within them have commas.. So split(",") doesnt work.. :(
@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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.