 <p>You just need to adjust the lookbehind to</p> <pre><code>(?&lt;!System\.)Windows\.Forms </code></pre> <p>Or with word boundary to be more precise:</p> <pre><code>(?&lt;!\bSystem\.)\bWindows\.Forms\b </code></pre> <p>See the <a href="http://regexstorm.net/tester?p=(%3F%3C!%5CbSystem%5C.)%5CbWindows%5C.Forms%5Cb&amp;i=I%20am%20using%20VS%20regex%20to%20try%20and%20delete%20the%20string%20Windows.Forms%20but%20not%20System.Windows.Forms&amp;r=" rel="nofollow">regex demo</a></p> <p>The lookbehind is checking the text <em>before</em> the current position meets some subpattern. So, the text you need to match and consume is <code>Windows.Forms</code>, but it should not be preceded with <code>System.</code>. Thus, the lookbehind (negative one) should only contain <code>System\.</code> (or <code>\bSystem\.</code>). </p> <p>Note that the dots must be escaped to match literal dots.</p>