问题
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