Ignore Regex negative lookahead?

Martin Geisler mg at daimi.au.dk
Tue Jul 15 10:34:55 CDT 2008


Bill Barry <after.fallout at gmail.com> writes:

> I am trying to get hg to ignore everything except a couple of
> folders within a directory (two folders actually), but the only way
> I can think of to do so would be to use a negative lookahead regex:
>
> Containers/(?!DNN-(Blue|Gray))
>
> That should pass for everything in the Containers folder except for
> the two folders "DNN-Blue" and "DNN-Gray" (which I need committed).

Okay -- I use a very similar regexp to ignore all .html files except
in two folders in the root of the repository:

  ^(?!api/|doc/).*\.html$

Try adding the ^ and & anchors? Also, it might be that you have
switched to the glob syntax for your .hgignore file. If that is the
case, then use

  syntax: regexp

to switch back to regular expressions.

> Except that it doesn't (negative lookaheads don't seem to be
> supported in the regexp ignore syntax). Is there anything I can do
> (or do I have the expression wrong? I have never written Python
> regexes, but I assume they are pretty much the same as the Perl ones
> that I have some experience with)?

Yes, they should be pretty much the same -- the reference is here:

  http://docs.python.org/lib/re-syntax.html

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.


More information about the Mercurial mailing list