http://www.perlmonks.org?node_id=302719

Wonko the sane has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

Here is what I am trying to do.

if ( m|/user/(?!prot/)| )
The problem is I cannot use negative lookahead to do it.

To do this, I have tried the following variations with no success.

#!/usr/local/bin/perl5.6.0 -w use strict; while ( <DATA> ) { chomp; #if ( m|/user/(?!prot/)| ) # Works #if ( m|/user/[^p]?[^r]?[^o]?[^t]?[^/]?| ) #if ( m|/user/([^p]*?[^r]*?[^o]*?[^t]*?[^/]*?)?| ) #if ( m|/user/[^p]+?[^r]+?[^o]+?[^t]+?[^/]+?| ) #if ( m|/user/([^p]*[^r]*[^o]*[^t]*[^/]*)?| ) { print qq{Disallow!! [$_]\n}; } else { print qq{Allowed. [$_]\n}; } } __DATA__ /user/prot/ /user/protrusions/ /user/a/ /user/backups
The only one that I want to print "Allowed", (not to match) is the first one "/user/prot/".

OT: Why cant I use negative lookahead?

Actually because I am trying to make a regex for an Apache LocationMatch section,
to disable some settings for all directories inside a users site, except for one,
'/user/prot'.
The regex engine in Apache though does not have lookaround assertion ability :(.

<LocationMatch /user/(?!prot/) > <Limit GET> order allow,deny deny from all </Limit> AllowOverride None </LocationMatch>
Any help is much appreciated.

Wonko