Fixing Negative Assertion for end of string
<p>I am trying to accept a capture group only if the pattern matches and there is not a specific word before the end of the group. I've tried a # of approaches and none seem to work, clearly I'm not getting the concept:</p>

<p><a href="https://regex101.com/r/iP2xY0/3" rel="nofollow">https://regex101.com/r/iP2xY0/3</a>
<a href="https://regex101.com/r/iP2xY0/4" rel="nofollow">https://regex101.com/r/iP2xY0/4</a></p>

<p>Regardless of what I do my capture group captures something and my goal is if the reject word exists in the middle of the pattern to return no match.</p>

<pre><code>RC:\*.*?(?P&lt;Capture&gt;(Bob|David|Ted|Alice))(?!Reject).*
</code></pre>

<ul>
<li>RC:* Hi Bob Smith&lt;\person></li>
<li>RC:* Hi David Jones *Notes Bla bla&lt;\person></li>
<li>RC:* Hi Ted Warren *Rejected &lt;\person></li>
</ul>

<p>Capture Namegrouop is supposed to return:</p>

<ul>
<li>Bob</li>
<li>David</li>
<li>''</li>
</ul>

<p>So "Reject" says if the NameGroup Capture is found followed by anything ending in <code>&lt;</code> capture it, if between the NameGroup and the &lt; the word <code>Reject</code> appears do not.</p>

<p>I would recommend putting your negative look-ahead at the beginning of your pattern. This first checks if your reject word exists in your string and only if it isn't there does it try to match the rest of the string:</p>

<p><code>(?!.*Rejected.*)RC:\*.*?(?P&lt;Capture&gt;(Bob|David|Ted|Alice)).*</code></p>

<p><a href="https://regex101.com/r/iP2xY0/6" rel="nofollow">https://regex101.com/r/iP2xY0/6</a></p>

python regex-negation regex-lookarounds