Saber Amani
Saber Amani

Reputation: 6489

Extract Url using Regex

I've been searching for at least 2hrs but I can't find any pattern to extract following Urls using regex. I went with too many patterns which described in many articles. But I couldn't find something useful.

For Example : Urls like following patterns.

http://google.com
http://www.google.com
http://www.image.google.com
http://google.com:8080
http://google.com:8080/default.aspx?param=1
http://google.com/default.aspx?param=1&param1=2

Update : Dear friends, It looks like I have to explain my issue in more details, I'm working on a simple proxy server using TCP components, My server listen to specific port when an incoming connection received. I'm extracting and reading all client request data. data contains headers and content types and etc like following :

GET http://www.bing.com/ HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US,en;q=0.7,fa;q=0.3
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)
Accept-Encoding: gzip, deflate
Host: www.bing.com
DNT: 1
Proxy-Connection: Keep-Alive

These are plain-text so I need to find and extract Urls for doing forwarding operations.

And any Url pattern you guess. Please, Any advice will be helpful.

Upvotes: 0

Views: 1250

Answers (2)

Ria
Ria

Reputation: 10357

Salam. Try this one:

https?://[^\s]+

Upvotes: 0

burning_LEGION
burning_LEGION

Reputation: 13460

https?://[\w\.]+\.\w+(:\d{1,5})?(/[\w?&.=]+)?

Upvotes: 3

Related Questions