 <p>What about:</p> <pre><code>import re lines = ''' &amp; $(-1,1)$ &amp; $(0,\infty)$ ''' matches = re.findall(r'\((.*),(.*)\)', lines) for (a,b) in matches: print "x: %s y: %s" % (a,b) </code></pre> <p>Outputs</p> <pre><code>x: -1 y: 1 x: 0 y: \infty </code></pre> <p>If you catch some weirdness, consider replacing <code>*</code> with <code>*?</code> to make the matching "not greedy".</p>