0

I am going to implement regex to catch url in strin. To do so, I have wrote regex expression but it only captures sub-part of expected input not all. How can I fix it so that it can catch all of the expected input and mark them as url?

expected input

ftp://joe:password@ftp.filetransferprotocal.com
http://www.google.com/search?q=good+url+regex&rls=com.microsoft:*&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1
https://some-url.com?query=&name=joe?filter=.#some_anchor
www.some-url.com?query=&name=joe?filter=.#some_anchor
www.some-url.edu?query=&name=joe?filter=.#some_anchor
www.some-url.gov?query=&name=joe?filter=.#some_anchor
www.some-url.co.uk?query=&name=joe?filter=.#some_anchor
www.some-url.xxx?query=&name=joe?filter=.#some_anchor
ww2.some-url.com?query=&name=joe?filter=.#some_anchor
http://en.wikipedia.org/wiki/Björn_Andrésen

my code is \(?\bhttp://[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]

Antony
  • 53
  • 1
  • 8

1 Answers1

1

This regular expression written by GitHub user gruber wil match all URLs. Just use that with a "g" (global) modifier so that it will find multiple instances.

Gausie
  • 4,291
  • 1
  • 25
  • 36