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:


I pass in the real path to a published jsp or some other file like this one:


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:


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 answers total)
Can't test this thoroughly now but try:
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 The Gods Must Be Petty   |   Got my viagra, need some contacts. Newer »
This thread is closed to new comments.