Tags:


Use a regular expression to parse a directory tree
April 11, 2006 11:25 AM   RSS feed for this thread 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)
Can't test this thoroughly now but try:
/home(?!/user2)/.*
posted by kenko at 11:38 AM on April 11, 2006


/home/(?!user2).* is a more straightforward version of that.
posted by kenko at 11:40 AM on April 11, 2006


Duh a lookahead. I can't believe it was that simple. Thanks kenko, you're a genius.
posted by toomuch at 11:42 AM on April 11, 2006


« Older I'm working on a boardgame in ...   |   Recommended off-shore vendor f... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
What is your favourite blog? March 30, 2008
What are some good blogs/sites that are like... February 21, 2008
What weblogs will make me smart and interesting... January 29, 2008
What are the most intellectually stimulating... November 20, 2007
Found a hidden webcam at work July 31, 2007