且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正则表达式来检索所有不包含特定字符串的URL

更新时间:2023-02-17 23:14:18

您可以使用负面展望正则表达式断言。

请参阅 http://www.perlmonks.org/?node_id=518444 http://www.regular-expressions.info/lookaround.html

  your_string(?!\?start =)


I am using the Google Analytics PHP API, and trying to use it to retrieve the most popular links on my website.

It works, but it retrieve some duplicates due to it retrieving URLs containing query strings. So basically, I want to retrieve all the links which do not contain the string "?start=" inside them. I think this can be done via regex (Google Analytics accepts regex filters), but don't know how.

Any ideas?

Thanks!

You can use negative look ahead regex assertion.

See http://www.perlmonks.org/?node_id=518444 and http://www.regular-expressions.info/lookaround.html

your_string(?!\?start=)