What am I doing wrong with this negative lookahead? Filtering out certain numbers in a regex
<p>I have a big piece of code produced by a software. Each instruction has an identifier number and I have to modify only certain numbers:</p>

<pre><code>grr.add(new GenericRuleResult(RULEX_RULES.get(String.valueOf(11)), new Result(0,Boolean.FALSE,"ROSSO")));
grr.add(new GenericRuleResult(RULEX_RULES.get(String.valueOf(12)), new Result(0,Boolean.FALSE,"Â£Â£Â£")));
etc...
</code></pre>

<p>Now, I am using SublimeText3 to change rapidly all of the wrong lines with this regex:</p>

<pre><code>Of\((11|14|19|20|21|27|28|31)\)\), new Result\(
</code></pre>

<p>This regex above allowed me to put "ROSSO" (red) in each line containing those numbers. Now I have to put "VERDE" (green) in the remaining lines. My idea was to add a <code>?!</code> in the Regex to look for all of the lines <em>NOT CONTAINING</em> those numbers.  </p>

<p>From the website <a href="https://regex101.com/" rel="nofollow">Regex101</a> I get in the description of the regex:</p>

<pre><code>Of matches the characters Of literally (case sensitive)
\( matches the character ( literally (case sensitive)
    Negative Lookahead (?!11|14|19|20|21|27|28|31)
    Assert that the Regex below does not match
       1st Alternative 11
       etc...
</code></pre>

<p>So why am I not finding the lines containing 12, 13, 14 etc?</p>

<p>Edit: the Actual Regex: <code>Of\((?!11|14|19|20|21|27|28|31)\)\), new Result\(</code></p>

<p>Your problem is that you are assuming a negative look ahead changes the cursor position, it does not.  </p>

<p>That is, a negative lookahead of the form <code>(?!xy)</code> merely verifies that the <em>next</em> two characters are not <code>xy</code>.  It does not then swallow two characters from the text.  As its name suggests, it merely <em>looks ahead</em> from where you are, without moving ahead!</p>

<p>Thus, if you wish to match further things beyond that assertion you must:</p>

<ul>
<li>negatively assert it is not <code>xy</code>;</li>
<li>then consume the two characters for whatever they are;</li>
<li>then continue your match.</li>
</ul>

<p>So try something like:</p>

<pre><code>Of\((?!11|14|19|20|21|27|28|31)..\)\), new Result\(
</code></pre>

python regex sublimetext3