I'm following up on a question since the question changed
Finding the regex for /<region>/<city>/<category>?
The answer that works is /(?:[^/]+)/?([^/]*)/?([^/]*)
and it outputs city in $1, category in $2 but I also just want to output $0 so can you help me modify it a little do achieve this?
It seems I'll finally be able to do what I want with this regex and it also applies to 2 earlier questions I asked
Can I use a python regex for letters, dashes and underscores?
How to represent geographical locations
My plan is to implement the functionality with multitenancy so that same software can serve large cities like sao paulo and delhi at same time with same code so I must make it very general and for all locations with same expression i.e. //
Plus the problem what we mean when we say e.g. "Search New York" - the region or the city? One piece of info for this is the output from google maps that defines "New York" where "region" corresponds to "administrative area":
{
"name": "New York",
"Status": {
"code": 200,
"request": "geocode"
},
"Placemark": [ {
"id": "p1",
"address": "New York, NY, USA",
"AddressDetails": {
"Accuracy" : 4,
"Country" : {
"AdministrativeArea" : {
"AdministrativeAreaName" : "NY",
"SubAdministrativeArea" : {
"Locality" : {
"LocalityName" : "New York"
},
"SubAdministrativeAreaName" : "New York"
}
},
"CountryName" : "USA",
"CountryNameCode" : "US"
}
},
"ExtendedData": {
"LatLonBox": {
"north": 40.8495342,
"south": 40.5788964,
"east": -73.7498543,
"west": -74.2620919
}
},
"Point": {
"coordinates": [ -74.0059731, 40.7143528, 0 ]
}
}, {
"id": "p2",
"address": "Manhattan, New York, NY, USA",
"AddressDetails": {
"Accuracy" : 4,
"Country" : {
"AdministrativeArea" : {
"AdministrativeAreaName" : "NY",
"SubAdministrativeArea" : {
"Locality" : {
"DependentLocality" : {
"DependentLocalityName" : "Manhattan"
},
"LocalityName" : "New York"
},
"SubAdministrativeAreaName" : "New York"
}
},
"CountryName" : "USA",
"CountryNameCode" : "US"
}
},
"ExtendedData": {
"LatLonBox": {
"north": 40.8200450,
"south": 40.6980780,
"east": -73.9033130,
"west": -74.0351490
}
},
"Point": {
"coordinates": [ -73.9662495, 40.7834345, 0 ]
}
} ]
}
:
However I don't think all the code has to be in the same file since I can make one file per region or some structure like that since the total number of regions ("states") for the whole world is not very much larger than the total number of countries but the total number of cities of the world is a large number. And it seems to have a file for every country included in the project is an easy and good way to organize.
Many thanks
Update
The regex I found useful is
application = webapp.WSGIApplication([('/([^/]+)/?([^/]*)/?([^/]*)',Handler),],debug=True)