.hgignore除某些子文件夹外的文件夹

时间:2014-02-24 10:41:34

标签: regex mercurial tortoisehg regex-negation

我想忽略一个文件夹但保留一些文件夹。 我尝试像这样的正则表达式匹配

syntax: regexp
^site/customer/\b(?!.*/data/.*).*

不幸的是,这不起作用。 我在这个answer中读到python只进行固定宽度的否定查找。

我想要的忽视不可能吗?

1 个答案:

答案 0 :(得分:0)

Python正则表达式很酷

Python支持否定预测查找(?=.*foo)。但它不支持任意长度的负向反向查找(?<=foo.*)。它需要修复(?<=foo..)

这意味着它绝对有可能解决您的问题。

问题

你有以下正则表达式:/customer/(?!.*/data/.*).* 我们来看一个输入示例/customer/data/name。它匹配是有原因的。

/customer/data/name
^^^^^^^^^^ -> /customer/ match !
          ^ (?!.*/data/.*) Let's check if there is no /data/ ahead
             The problem is here, we've already matched "/"
             so the regex only finds "data/name" instead of "/data/name"
          ^^^^^^^^^ .* match !

修复你的正则表达式

基本上我们只需删除一个正斜杠,我们添加一个锚^以确保它是字符串的开头,并确保我们只使用customer匹配\b^/customer\b(?!.*/data/).*

Online demo

相关问题