Skip to content

Instantly share code, notes, and snippets.

@brettkelly
Created January 18, 2011 18:35
Show Gist options
  • Save brettkelly/784905 to your computer and use it in GitHub Desktop.
Save brettkelly/784905 to your computer and use it in GitHub Desktop.
import re
import urllib
reg = '[\&|\?]q=(?P<terms>[^\?\&$]+)'
rx = re.compile(reg)
tests = [
'http://www.evernote.com/about/kb/search?lang=en&q=test',
'http://www.evernote.com/about/kb/search?q=foo+bar&lang=en',
'http://www.evernote.com/about/kb/search?lang=en',
'I AM A FAKE URL',
'http://www.evernote.com'
]
results = {}
for t in tests:
mo = rx.search(t)
if(mo):
terms = urllib.unquote(mo.group('terms'))
if terms in results:
results[terms] += 1
else:
results[terms] = 1
print results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment