Honing the .hgignore file using a negative lookahead

久未见 提交于 2019-12-12 03:16:38

问题


I've looked at a handful of the other Hg hgignore file questions, but I haven't been able to get my regex to work.

Imagine these files:

Projects/search.intrasearch/newUI/override/xslt/foo.xsl
Projects/search.intrasearch/newUI/default/
Projects/search.intrasearch/oldUI/baz/

I want to ignore the second two lines, but not the first. So, in Mercurial, I want to include files in the newUI/override directory and it's children, but that's it. In the real system, there are a bunch more directories than above, so simply excluding oldUI and default won't work. I need a method of inclusion.

This works in a regex tool, but not in Mercurial:

(?i)Projects/search\.intrasearch/(?!newUI/override).*


回答1:


I finally figured this out by using a combination of two regex's:

(?i)Projects/search.*?/newUI/(?!override).*
(?i)Projects/search[^/]*/(?!newUI).*

This seems to successfully exclude anything that's a sibling to newUI and anything that's a sibling to override.



来源:https://stackoverflow.com/questions/8996920/honing-the-hgignore-file-using-a-negative-lookahead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!