tags:

views:

31

answers:

1

I'm writing a program which needs to traverse a set of directories. Tried to use the following code:

file.eachDirMatch(/.*[^.svn]/){ //some code here }

But that ended up match none of my directories. I realize this boils down figuring out the right regex hang head in shame but even after revisiting some Java Regular Expression documentation I thought this should work.

A: 

Try this regex instead:

/^(?!\.svn).*/

(This assumes that your language's regex flavor supports negative lookaheads.)

Amber
Just tried this and still nothing
algernon
Try a basic `/.*/` then and make sure that you're actually matching against *something* - `.*` should match anything passed in, so it may not be the regex at fault.
Amber
/.*/ did not work but ~".*" did. The Groovy documentation made it seem like i could use the /-notation. Tried ~".*[^svn]" and that did the trick but I don't like the fact that it will match a directories other than ".svn"
algernon
Okay finally figures out what i was doing wrong. Your regex did work correctly I just needed to add the "~" before either a String or / notation of a pattern. Thanks for the help
algernon