Created
June 8, 2011 21:20
-
-
Save akrito/1015431 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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