 <p>As some other answers already said, there's no need to use a regular expression here. A simple <code>split</code> and some filtering will do nicely:</p> <pre><code>lines = data.split("\n") #assuming data contains your input string sld, tld = [[x.split("=")[1] for x in lines if x[:3] == t] for t in ("SLD", "TLD")] result = [x+y for x, y in zip(sld, tld)] </code></pre>