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

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

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


From: Aaron Bentley
Subject: [Gnu-arch-users] Preventing matches in regular expressions
Date: Mon, 09 Aug 2004 15:29:53 -0400
User-agent: Mozilla Thunderbird 0.5 (X11/20040309)

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?

Aaron

--
Aaron Bentley
Director of Technology
Panometrics, Inc.




reply via email to

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