用于排除 URL 的正则表达式
我与一家电子邮件公司合作,该公司有一个功能,他们可以抓取您的网站以提供自定义内容。我能够让蜘蛛根据我提供的正则表达式模式忽略 url。
对于该系统,模式以“/”开始和结束。
我想做的是忽略 http://www.website.com/2011/10 但允许 http://www.website.com/2011/10/title-of-page.html
我本以为下面的模式会起作用,因为它没有尾部斜杠,但没有运气。
有什么想法吗?
/http:\/\/www\.website\.com\/[0-9][0-9][0-9][0-9]\/[0-9][0-9]/
I working with an email company that has a feature where they spider your site in order to provide custom content. I have the ability to have the spider ignore urls based on the regex patterns I provide.
For this system a pattern starts and ends with a "/".
What I'm trying to do is ignore http://www.website.com/2011/10 BUT allow http://www.website.com/2011/10/title-of-page.html
I would have thought the pattern below would work since it does not have a trailing slash but no luck.
Any ideas?
/http:\/\/www\.website\.com\/[0-9][0-9][0-9][0-9]\/[0-9][0-9]/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的正则表达式匹配 URL 的部分,因此您需要告诉它不要在其后添加斜杠:
如果您还想避免其他部分匹配,例如
http://www .website.com/2011/100
,那么额外的单词边界可能帮助:Your regex matches a part of the URL, so you need to tell it not to allow a slash to follow it:
If you want to also avoid other partial matches like in
http://www.website.com/2011/100
, then an additional word boundary might help:这取决于正则表达式引擎,但您可能可以使用 $(如果 URL 预先标记化)或空格和分隔符的匹配
It depends on the regexp engine but you can probably either use $ (if the URL is tokenised beforehand) or a match for whitespace and delimiters