views:

50

answers:

1

Hate coming up with titles. I need something that'll actually capture the following:

site.com/500/ (a number as the first param)

site.com/500/ABC/ (a number and a 3 letter code)

site.com/500/ABC/DEF/ (a number and 2x 3 letter codes)

What I have been messing with:

^(\d+/)?(\w{3}/)?(\w{3}/)?$

That sort of works but includes the slashes in the arguments (so I end up with "500/"). Moving the slashes outside of the brackets won't match /500/ABC/ since the ? only works on the slash.

Obviously I can make it in multiple ones but I'm sure there's a way to do it in one go.

As well, I only want the actual arguments, since as I said it can work but ends up adding slashes to them, which isn't too good.

Thanks for any help.

+1  A: 

how about ..

((\d+/)|(\d+/\w{3}/)|(\d+/\w{3}/\w{3}/))$

the result will be ..

site.com/500/ABC/DEF/ => 500/ABC/DEF/
site.com/500/ABC/ => 500/ABC/
site.com/500/ = 500/
ala
That does seem to work but doesn't seem to work too well in django from what I tested. I should've specified it in the original post, but thanks for the help too.
damnitshot