0

I found this post, and now i want to use that regular expression too What characters are allowed in a Google App Engine Key?

However, in my handler i write something like

('/xxx/[a-zA-Z0-9-_]', MyHandler)

but it doesn't work...when i try to access a link it says not found...i tried many variations but can't seem to make it happen...Help?!

EDIT : Thanks for the help guys...such a foolish mistake :)

Community
  • 1
  • 1
Teshte
  • 624
  • 1
  • 7
  • 26
  • 1
    Without seeing your code, this could be lots of things, but perhaps you meant `('/xxx/[a-zA-Z0-9-_]+', MyHandler)` – Jesse Rusak Apr 07 '13 at 15:31
  • the problem is surely caused by the regular expression...because if i put something like "(\w+)"...everything works fine – Teshte Apr 07 '13 at 15:32

3 Answers3

3

Your handler currently allows only exactly one character. Also, for safety, the dash should always be at the end of a character class, lest it designate a range:

('/xxx/[a-zA-Z0-9_-]*', MyHandler)
Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
3

Your regular expression matches just one character after the /xxx/ part. You need to specify that you want 1 or more by adding the + multiplier:

('/xxx/[a-zA-Z0-9-_]+', MyHandler)

Now your expression matches anything that has at least 1 character, not just 1 and nothing more.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
1

Keys can also only be 500 bytes long, so I am using the following

pattern = re.compile('^[0-9A-Za-z._-]{1,500}$')
valid = bool(pattern.match('key-name-to-test'))

Old question, but I thought I would add this for future views.

Community
  • 1
  • 1
roridge
  • 51
  • 4