1

我希望匹配(java regex)属于某个域的所有 url,除了看起来像查询字符串的那些。

例如,我希望匹配

http://www.thehindu.com/arts/music/marrying-keys-to-chips/article4061904.ece

但避免

http://www.thehindu.com/arts/music?article=23417

我尝试了以下方法,但它允许上述两种模式。

+^http://www\.thehindu\.com([^\?=])*
4

3 回答 3

1

关于什么

if (yourString.matches("(http://)?www\\.thehindu\\.com[^\\?=]*") {
    // match --> doesn't look like a query
} else {
    // no match --> looks like a query or completely different url
}
于 2012-11-05T10:11:49.570 回答
0

我想 regexp 不是必需的,尝试寻找问号?

于 2012-11-05T10:13:55.830 回答
0

试试这个:

(^|\s)http:\/\/www\.thehindu\.com([^\?])*(\s|$)

其中 (^|\s) 和 (\s|$) 是您期望在 url 之间的分隔符。如果需要,请在其中添加更多内容。

于 2012-11-05T10:16:57.277 回答