REGEX formulating conditions
<p>Just started learning python and regex. </p>

<pre><code>My regex:
\b\d+\s+([A-Za-z]* |[A-Za-z]*\s+[A-Za-z]*)\s+\D+..
</code></pre>

<p>using <a href="https://regex101.com/" rel="nofollow">https://regex101.com/</a> </p>

<p><strong>string 1:</strong> <a href="https://i.imgur.com/XNuXftW.jpg" rel="nofollow">https://i.imgur.com/XNuXftW.jpg</a> (why does Beer has whitespaces while carrot/chocolate dont have?)</p>

<p><strong>string 2</strong><a href="https://i.imgur.com/nrl2FPB.jpg" rel="nofollow">https://i.imgur.com/nrl2FPB.jpg</a>  (adding further more of \s+[A-Za-z] in the capture group doesnt seem to be working anymore, WHY?)</p>

<p><strong>string 3</strong>: <a href="https://i.imgur.com/qH0Z7Hi.jpg" rel="nofollow">https://i.imgur.com/qH0Z7Hi.jpg</a> (same as string 2 problem)</p>

<p>my question is how do i continue to formulate such that it will encompass the above conditions? thank you</p>

<p>in the case that you need to test it yourself, i have provided the strings as below.</p>

<p>=</p>

<p>I guess the the space before "|" is the one causes it captures "beer " in <strong>string 1 case</strong> "Chocolate cake" does not happen as "beer " as it is matched with the second regex which is </p>

<pre><code>[A-Za-z]*\s+[A-Za-z]*
</code></pre>

<p>for <strong>string 2</strong> 
    [A-Za-z]<em>\s+[A-Za-z]</em>
regex matches exactly two words </p>

<p>How about try below regex, modified from trincot</p>

<pre><code>(?&lt;=\s\s)(\w+\s)+(\w+)(?=\s\s)
</code></pre>

python regex