Use a regular expression to parse a directory tree
April 11, 2006 11:25 AM
Subscribe
I'm trying to write a regex that gets passed into a java class to validate that a file is in a certain directory structure.
Okay folks here's the deal. I have a closed source java class with a method that will tell me if a particular web resource is in one of it's predefined directory structures. The directory structures are defined as regular expressions in an XML file like this:
/var/www/.*
/home/user1/www/.*
I pass in the real path to a published jsp or some other file like this one:
/home/user1/www/test.jsp
and this method should return true if the file is in one of it's configured directory structures.
I'm trying to write a regular expression that will match all files/directories in the /home file tree except for a single user. Something like:
/home/.*
/home/^user2
but i want it in a single regular expression. That way if i pass in /home/user1/test.jsp I get a true but if I pass in /home/user2/test.jsp I get a false. I've been toying with something like "/home/[.*&&[^(user2/.*)]]" but it doesn't work. Hopefully that makes sense. Anyone, anyone?
posted by toomuch to computers & internet (3 comments total)
/home(?!/user2)/.*
posted by kenko at 11:38 AM on April 11, 2006