Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6613897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:16:23+00:00 2026-05-25T20:16:23+00:00

This was posted to me < * @google.com> wrote: Hi Niklas, If you just

  • 0

This was posted to me

<*@google.com> wrote:

Hi Niklas,
If you just want to map this: /region/city/category/ supposing
its only
this valid characters: [a-zA-Z0-9_]
you can do the following:
– main.py

application =
webapp.WSGIApplication([(‘/([-\w]+)/([-\w]+)/([-\w]+)’,
handler)],debug=True)

and on your handler:
class Handler(webapp.RequestHandler):
def get(self, region, city, category):
# Use those variables on the method
Hope this helps!

My webapp is suppossed to handle URI like <region>/<city>/<category> with optional city and category e.g.

/rio_de_janeiro/grande_rio_de_janeiro/casas? #<region>/<city>/<category>
/gujarat/ahmedabad/vehicles-for_sale #<region>/<city>/<category>
/rio_de_janeiro/grande_rio_de_janeiro/ #<region>/<city>
/delhi #<region>

Etc Now I want to enable a request handler that can take optional arguments divided by the separator /. If I use the regex '/(.*) and variables in the request handler the first varible becomes a/b and the second variable becomes b so that is nearly what I want but a and b as 2 different variables instead. The regex I tried for the request handler is

application = webapp.WSGIApplication([('/(.*)',MyPage),

And the function head of my request handler is

class MyPage(RequestHandler):
    def get(self, location='frankfurt', category='electronics'):

To enable an HTTP query e.g. /frankfurt, /frankfurt/, /frankfurt/electronics, /madrid/apartments, /newyork, etc allowing all possible combinations. Can you advice me a regex that can achieve what I want? I want functionality like a mod_rewrite but for GAE.

Thanks

Clarification

It’s just a question of “make the directory a variable” so to clarify here are some examples how it should behave

‘/frankfurt’, – put ‘frankfurt’ in variable 1
‘/frankfurt/’, – put ‘frankfurt’ in variable 1
‘/frankfurt/electronics’, – put ‘frankfurt’ in variable 1 and ‘electronics’ in virable 2
‘/frankfurt/electronics/’, same as above
‘/eu/frankfurt/electronics’, same as above i.e. only last 2 groups count
‘/eu/frankfurt/electronics/’, same as above
‘toronto/lightnings’, doesn’t start with / so shan’t work
‘toronto/lightnings/’, as above
‘lima/cars/old’, as above
‘lima/cars/old/’ as above

Typical cases I want to handle is /region/city/category i.e. if I apply the example to Brazil it could be /rio_de_janeiro/grande_rio_de_janeiro/casas? for /region/city/category or for India it could be /delhi/delhi/for_sale or /gujarat/ahmedabad/vehicles-for_sale

Solution

As far as I can tell the solution from the answer works for my purposes:

/(?:[^/]+)/?([^/]*)/?([^/]*)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:16:23+00:00Added an answer on May 25, 2026 at 8:16 pm

    You can try

    /(?:[^/]+)/?([^/]*)/?([^/]*)

    which will put ‘a/b’ in variable 1, ‘a’ in variable 2 and ‘b’ in variable 3. Not sure if that is what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(I just posted this in the NUnit discussion group on groups.google.com) Under VS 2008,
I also posted this question on the Google Group https://groups.google.com/forum/?fromgroups#!topic/d3-js/DYiVeC544ws , but saw that
I was reading this blog( http://googlepublicpolicy.blogspot.com/2009/06/https-security-for-web-applications.html ) posted by google on not enabling HTTPS
My problem is similar to what this person has posted: http://groups.google.com/group/android-developers/browse_thread/thread/216839d1c45cefa9/a1b9517d2064726b?show_docid=a1b9517d2064726b That is, my
This question was initially posted on Google Moderator for the AndroidDev Office Hours Hangout
[I have posted this at the Django users | Google Groups also.] Using the
I posted this back in May on the [android-developers] Google Group. I never heard
I posted this earlier on wordpress.stackexchange.com. However, never got a reply. Hence, trying my
(Question also posted here: http://www.google.com/support/forum/p/Android+Market/thread?tid=68dc1f694537c7dc&hl=en ) http://developer.android.com/guide/publishing/publishing.html recommends searching for apps by Developer Name
I found some sample code posted at https://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/4d45e9ea5471cba4/4519371a77ed4a74?hl=en&pli=1 for self installing a Windows Service.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.