Have you checked pyparsing ?
from pyparsing import Word, alphas
text = "me (I) you (You) him (He) her (She)"
parser = "(" + Word(alphas).setResultsName("value") + ")"
out = open("myfile.txt", "w")
for token, start, end in parser.scanString(text):
print >>out, token.value
Conclusion:
I
You
He
She
source
share