Skip to content

Instantly share code, notes, and snippets.

@akrito
Created June 8, 2011 21:20
Show Gist options
  • Save akrito/1015431 to your computer and use it in GitHub Desktop.
Save akrito/1015431 to your computer and use it in GitHub Desktop.
import re, sys
to_find = sys.argv[1]
def find_closing_paren(string, start):
current = start
num_open = 1
for c in string[start:]:
current += 1
if c == '(':
num_open += 1
elif c == ')':
num_open -= 1
if num_open == 0:
return current
for fn in sys.argv[2:]:
with open(fn) as fd:
content = fd.read()
for m in re.finditer(to_find + r'\(', content):
match = find_closing_paren(content, m.end())
print content[m.start():match]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment