1

我有以下网址

http://mysite/us/product.aspx
http://mysite/de/support.aspx
http://mysite/spaces/product-space
http://mysite/spaces/product-space/forums/this is my topic
http://mysite/spaces/product-space/forums/here is another topic
http://mysite/spaces/support-zone
http://mysite/spaces/support-zone/forums/yet another topic
http://mysite/spaces/internal
http://mysite/spaces/internal/forums/final topic
http://mysite/support/product/default.aspx

我想使用正则表达式添加一个抓取规则(这是与 SharePoint 2010 搜索相关的),它排除了不包含的 URL /forums/*,只留下论坛主题 URL。

我想要一个排除 URL 的规则,../spaces/space1../spaces/space2保留所有其他的 URL,包括包含/forums/

即这里是我想用正则表达式识别的结果(将在 SharePoint 搜索中的“排除”规则中使用):

http://mysite/spaces/product-space
http://mysite/spaces/support-zone
http://mysite/spaces/internal

使这些结果与正则表达式不匹配(因此不被此规则排除)

http://mysite/us/product.aspx
http://mysite/de/support.aspx
http://mysite/spaces/product-space/forums/this is my topic
http://mysite/spaces/product-space/forums/here is another topic
http://mysite/spaces/support-zone/forums/yet another topic
http://mysite/spaces/internal/forums/final topic
http://mysite/support/product/default.aspx

有人可以帮我吗?我整个早上都在看这个,我的头开始疼——我无法解释,我只是没有得到正则表达式结构。

谢谢

凯文

4

2 回答 2

2

...在Multi-line模式下(假设每行一个 URL),这对我有用:

(.*?\/forums\/.*?)$

希望这可以帮助

更新:

鉴于您的评论,使用的模式可能是:

.*/spaces/(?!.*/).*

基本上说匹配线之后有/spaces/但不再有/(如您在评论中所述的标准)。


使用@rvalvik 的正则表达式建议(另一种非常好的方式),您的答案将如下所示:

^(?!.*/forums/).*/spaces/.*
于 2013-03-07T15:28:09.653 回答
2

您可以使用前瞻来断言/forum/URL 中的内容(如果存在则匹配):

^(?=.*/forums/)

或否定前瞻断言它不存在:

^(?!.*/forums/)

更新:

此正则表达式将匹配您在“排除”列表中的网址:

^(?!.*/forums/).*/spaces/(?:space1|space2)

简而言之,我们排除所有包含/forums/使用负前瞻的 url,然后我们匹配任何包含/spaces/space1or的内容/spaces/space2

但是,有些系统要求您匹配整行,在这种情况下,您需要.*在末尾添加 a:

^(?!.*/forums/).*/spaces/(?:space1|space2).*
于 2013-03-07T15:34:37.430 回答