Regular expression to find string with iterating letters on the end
<p>Can someone help me with this kind of regular expression matching?</p>

<p>For example, I'm searching through list containing different strings with a letter iterating at the end of the string:</p>

<ul>
<li>MonsterA</li>
<li>MonsterB</li>
<li>MonsterC</li>
<li>HeroA</li>
<li>HeroB</li>
<li>HeroC</li>
<li>...</li>
</ul>

<p>What I need this script to return is only the preceding part of the string, in this example <strong>Monster</strong> and <strong>Hero</strong>. </p>

<p>You could use a <em>positive lookahead assertion</em> <code>(?=...)</code> to check the words ends in a single uppercase character and then use word boudaries <code>\b...\b</code> to ensure it does not match patterns that arent whole words:</p>

<pre><code>&gt;&gt;&gt; text = "This re will match MonsterA and HeroB but not heroC or MonsterCC"
&gt;&gt;&gt; re.findall(r"\b[A-Z][a-z]+(?=[A-Z]\b)", text)
['Monster', 'Hero'] 
</code></pre>

<p><code>re.findall</code> returns all such matches in a list. </p>

python regex string loops iterator