Skip to content

Instantly share code, notes, and snippets.

@melpomene
Created March 24, 2013 13:25
Show Gist options
  • Save melpomene/5231970 to your computer and use it in GitHub Desktop.
Save melpomene/5231970 to your computer and use it in GitHub Desktop.
"Explain regex" terminal utility.
#!/usr/bin/env python
# encoding: utf-8
import sys, urllib2, urllib
from bs4 import BeautifulSoup
if __name__ == '__main__':
if len(sys.argv) < 2:
print "Called with './explainregex therege(x)?'"
else:
page = urllib2.urlopen('http://rick.measham.id.au/paste/explain.pl?regex='+ urllib.quote(sys.argv[1]))
html = BeautifulSoup(page)
for pre in html('pre'):
print pre.contents[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment