-4

I have a string like "test http://www.bing.com test". I want to extract just the url ("http://www.bing.com") from this string. How do I go about doing it? How would the regex look like?

admdrew
  • 3,711
  • 4
  • 24
  • 39
AnoojNair
  • 481
  • 3
  • 11
  • 18
  • 4
    And you really couldn't find a regex with a search for "regex match url" or something similar ? – adeneo Sep 02 '14 at 19:30

2 Answers2

0

You can use this regex:

((?:https?://)?www\.\S+)

Working demo

enter image description here

Federico Piazza
  • 28,830
  • 12
  • 78
  • 116
0

There is a nice URl parsing plug-in for jQuery you can use that will clean up the source text a bit before doing it's job.

https://github.com/websanova/js-url

Lucky Edward
  • 126
  • 11