What I am trying to do: Parse a query for a leading or trailing ? which will result in a search on the rest of the string.
"foobar?" or "?foobar" results in a search. "foobar" results in some other behavior.
This code works as expected in the interpreter:
>>> import re
>>> print re.match(".+\?\s*$","foobar?")
<_sre.SRE_Match object at 0xb77c4d40>
>>> print re.match(".+\?\s*$","foobar")
None
This code from a Django app does not:
doSearch = { "text":"Search for: ", "url":"http://www.google.com/#&q=QUERY", "words":["^\?\s*",".+\?\s*$"] }
...
subQ = myCore.lookForPrefix(someQuery, doSearch["words"])
...
def lookForPrefix(query,listOfPrefixes):
for l in listOfPrefixes:
if re.match(l, query):
return re.sub(l,'', query)
return False
The Django code never matches the trailing "?", all other regexs work fine.
And ideas about why not?