python regex matching between multiple lines and every other match
<p>So I've been playing around with this for a few days and here is what I am looking for and the regex I have now. I have a file in this  format (there are some other fields but I have omitted those:</p>

<p>I just want to match the bold text </p>

<pre><code>ADDR 1 - XXXXXX   ADDR 1 - **XXXXXX**

ADDR 2 - XXXXXX   ADDR 2 - XXXXXX

ADDR 1 - XXXXXX   ADDR 1 - **XXXXXX**

ADDR 2 - XXXXXX   ADDR 2 - XXXXXX
</code></pre>

<p>The regex I have  written only matches the first ADDR 1 - XXXXX, but I need to match all instances of the bolded XXXXX.</p>

<pre><code>re.findall(r'ADDR 1- .*? ADDR 1-(.*?)(?=ADDR 2-)', lines, re.DOTALL)
</code></pre>

<p>Any suggestions? I feel like I might be  missing something simple, but not sure.</p>

<p><strong>Code:</strong></p>

<pre><code>import re

str= """
ADDR 1 - XXXXXX ADDR 1 - ABCDEF

ADDR 2 - XXXXXX ADDR 2 - XXXXXX

ADDR 1 - XXXXXX ADDR 1 - UVWXYZ

ADDR 2 - XXXXXX ADDR 2 - XXXXXX
"""

m = re.findall(r".*ADDR\s+1\s+-\s+(.*)",str)
print m
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>C:\Users\dinesh_pundkar\Desktop&gt;python c.py
['ABCDEF', 'UVWXYZ']

C:\Users\dinesh_pundkar\Desktop&gt;
</code></pre>

<p><strong>How it works:</strong></p>

<pre><code>.*ADDR\s+1\s+-\s+(.*)
</code></pre>

<p><img src="https://www.debuggex.com/i/90HlB1jEj2mJ_4V_.png" alt="Regular expression visualization"></p>

<p><a href="https://www.debuggex.com/r/90HlB1jEj2mJ_4V_" rel="nofollow">Debuggex Demo</a></p>

<p>Lets take a line - <strong>ADDR 1 - XXXXXX ADDR 1 - ABCDEF</strong></p>

<ul>
<li><code>.*ADDR</code> will match <em>ADDR 1 - XXXXXX ADDR</em>. Since <code>.*</code> match anything and by nature regex are greedy, so to stop I have add <code>ADDR</code> after <code>.*</code></li>
<li><code>\s+1\s+-\s+(.*)</code> will match rest  <em>1 - ABCDEF</em>. <code>\s+1\s+-\s+</code> is required since we need to match <em>ADDR 1</em> and not <em>ADDR 2</em>. <code>(.*)</code> will match <em>ABCDEF</em> and store it.</li>
</ul>

python regex