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: Andrew Suffield
Subject: Re: [Gnu-arch-users] Preventing matches in regular expressions
Date: Wed, 11 Aug 2004 20:14:20 +0100
User-agent: Mutt/1.5.6+20040722i

On Wed, Aug 11, 2004 at 08:42:48AM +0200, Jan Hudec wrote:
> On Tue, Aug 10, 2004 at 20:42:25 +0100, Andrew Suffield wrote:
> > On Mon, Aug 09, 2004 at 03:29:53PM -0400, Aaron Bentley wrote:
> > > 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$
> > 
> > Yes, that's right. It's an old and rather evil trick.
> > 
> > > 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?
> > 
> > Well, you can implement regexp extensions that construct these
> > things. They can get a bit memory-hungry though.
> > 
> > More normally you just step outside the bounds of regexps though. Perl
> 
> Lookahead/lookback assertions are perfectly regular. They definitely can
> be expressed as a NFA.

Did you read what I wrote? Yes, it can be done, but it's not usually
the best way to do it. Expressing these things as an NFA tends to suck
- you can go memory-hungry or slow, depending on how you approach it.

> > does it by having regexps that aren't; perlre cannot be expressed as
> > an NFA, although it still uses one to do *most* of the work.
> 
> Perl expression are not regular, but for completely different reasons.

Actually, this is one of the primary reasons why perlre isn't a
classical regexp, not that it's relevant. Not because it *couldn't* be
done as an NFA, but because it *shouldn't*. (Backreferences and
negation are two others off the top of my head; most of the more
obscure features are coincidental, not reasons for the design of the
perlre engine).

-- 
  .''`.  ** Debian GNU/Linux ** | Andrew Suffield
 : :' :  http://www.debian.org/ |
 `. `'                          |
   `-             -><-          |

Attachment: signature.asc
Description: Digital signature


reply via email to

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