I started out thinking I need to get a dot followed by 3 or 4 letters and then match everything before it including the slash it finishes with, but I couldn't get it to work and it got quite messy. When I posted this: ((.*\\)*.*)(\....(.)?)? it was way more complicated than it needed to be. I was playing on http://www.regular-expressions.info/javascriptexample.html while looking at the cheat sheets from http://www.regular-expressions.info but nothing was working.
The I remembered something from Mastering Regular Expressions ( a great and surprisingly interesting book) - think about exactly what you want your regex to say (seems so obvious). All I wanted was everything that wasn't a dot which is sometims followed by a dot and some other letters: ([^.]*)(\.*)? BUT, writing this email has made me realize that the best answer is just: ^[^.]* (Give me everything from the start that's not a dot)! I could kick myself - it's so simple. I guess that is brute force - definitely not the work of a ninja. Cheers Dave On Mon, Oct 4, 2010 at 9:17 PM, silky <michaelsli...@gmail.com> wrote: > On Mon, Oct 4, 2010 at 9:02 PM, Peter Gfader <pe...@gfader.com> wrote: > > Hi David > > How did you solve it? > > Did you brute force it or using some Regex Ninja tool that you want to > > share? > > (I'm not David, but...) Interesting question .... > > Arguably, it's easy to see how he arrived that the correct answer > (which is valid for the given examples, but not if the path contains a > folder a dot, which wasn't in the requirements, so may be > meaningless). I actually find the first instances hard to understand, > and I don't think I would've logically gotten from *them* to the > current answer without a fresh mind. > > I have vague memories of once upon a time using this: > http://www.weitz.de/regex-coach/ > > But these days anything I do in regex is so simple that I can just > test it inside c# itself. Of course, you probably already know about > http://www.regular-expressions.info/ , but they do seem to have a list > of tools, I haven't used them before though. > > > > .peter.gfader. > > http://blog.gfader.com/ > > http://twitter.com/peitor > > -- > silky > > http://dnoondt.wordpress.com/ > > "Every morning when I wake up, I experience an exquisite joy — the joy > of being this signature." >