【发布时间】:2011-08-31 15:44:52
【问题描述】:
我有一个很好的 URL 捕捉正则表达式,但我有一个问题.. 我不想从 are togl.me 捕捉 url...我的正则表达式是:
(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))
这是正则表达式模式:
(?xi)
\b
( # Capture 1: entire matched URL
(?:
https?:// # http or https protocol
| # or
www\d{0,3}[.] # "www.", "www1.", "www2." … "www999."
| # or
[a-z0-9.\-]+[.][a-z]{2,4}/ # looks like domain name followed by a slash
)
(?: # One or more:
[^\s()<>]+ # Run of non-space, non-()<>
| # or
\(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
)+
(?: # End with:
\(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
| # or
[^\s`!()\[\]{};:'".,<>?«»“”‘’] # not a space or one of these punct chars
)
)
不要捕获来自 http://togl.me 的 URL。我可以在捕获 URL 后使用 parse_url 来检查域名,但为什么需要呢?
【问题讨论】:
-
parse_url()有什么问题? -
NullUserException,时隔近三年,我看到你的回复完全正确。谢谢,