gnu-arch-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnu-arch-users] Preventing matches in regular expressions


From: Jan Hudec
Subject: Re: [Gnu-arch-users] Preventing matches in regular expressions
Date: Tue, 10 Aug 2004 09:53:42 +0200
User-agent: Mutt/1.5.6+20040722i

On Mon, Aug 09, 2004 at 15:29:53 -0400, Aaron Bentley wrote:
> Hi all,
> 
> I'd like to have a "categorize" command in Fai that would rewrite the 
> .arch-inventory and =tagging-method rules.  I'd like to be able to do:
> 
> --
> $fai categorize --local --backup --extension .zip
> $fai categorize --local --unrecognized fox.zip
> --
> 
> That would add or update the regexes in the .arch-inventory.  But since 
> backup is tried before unrecognized, the rule for backup must match 
> every zip file except 'fox.zip'
> 
> Here's what I've finally come up with, using the example 'fox.zip':
> 
> backup ^(.{0,2}|.{4}.*|[^f]..|.[^o].|..[^x])\.zip$
> 
> The bit between parentheses translates as:
> Match anything with two or fewer characters
> Match anything with four or more characters
> Match anything with three characters that doesn't start with 'f'
> Match anything with three characters that doesn't have 'o' in the middle
> Match anything with three characters that doesn't end with 'x'
> 
> Tests show that it does work:
> --
> $ cat .arch-inventory
> backup ^((.{0,2}|.{4}.*|[^f]..|.[^o].|..[^x])\.zip)$
> 
> # I'm matching anything that matches .zip that isn't caught by
> # the earlier match.  Which is just "fox.zip".
> unrecognized ^*.zip$
> 
> $ tla inventory
> B  f.zip
> B  fax.zip
> B  flox.zip
> U  fox.zip
> B  fx.zip
> --
> 
> But man, oh man, that's an ugly regex, and it'll only get less readable 
> with longer filenames and multiple filenames.
> 
> Does anyone know a better general solution?

A general solution would be to use a negative lookahead assertion. But
I don't know whether they are implemented in hackerlab. Hackerlab has
something called a "cut" operator. I can't find it's documentation so
I am not sure whether it can be used, but I think it can.

-------------------------------------------------------------------------------
                                                 Jan 'Bulb' Hudec 
<address@hidden>

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]