使用正则表达式提取网址 [英] Extract Url using Regex

查看:163
本文介绍了使用正则表达式提取网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了至少 2 小时,但我找不到任何使用正则表达式提取以下 URL 的模式.我使用了很多文章中描述的太多模式.但我找不到有用的东西.

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.

例如:网址如下图.

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

更新:亲爱的朋友们,看来我必须更详细地解释我的问题,我正在使用 TCP 组件开发一个简单的代理服务器,我的服务器在传入时侦听特定端口连接收到.我正在提取和读取所有客户端请求数据.数据包含标题和内容类型等,如下所示:

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

这些是纯文本,所以我需要找到并提取 URL 以进行转发操作.

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

以及您猜到的任何 URL 模式.拜托,任何建议都会有所帮助.

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

推荐答案

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

这篇关于使用正则表达式提取网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆