0

Given a string of text which could possibly contain multiple urls all starting with http://

for example:

someString = "Text amongst words and links http://www.text.com more text more text another http http://www.word.com"

How can I extract all the urls from a string like the one above?

Leaving just

http://www.text.com

http://www.word.com

2 Answers 2

1

This should work:

>>> for url in re.findall('(http://\S+)', someString): print url
... 
http://www.text.com
http://www.word.com
Sign up to request clarification or add additional context in comments.

Comments

1

You want regular expressions.

In python: https://docs.python.org/2/library/re.html

Regular expression to evaluate: http://daringfireball.net/2010/07/improved_regex_for_matching_urls

Shouldn't take you long from there

Comments

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.