-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,790
  • 4
  • 27
  • 39
AnoojNair
  • 491
  • 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
  • 30,085
  • 15
  • 87
  • 123
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
  • 136
  • 11