title: How to find indexes of all non-matching characters with a JS regex?
body: <p>I've got a string and I want to get an array with the indexes (positions) of the characters in this string that do not match a certain regex criteria.</p>
  
  <p>The issue here is that if I write it like this: </p>
  
  <pre><code>let match;
  let reg = /[A-Za-z]|[0-9]/g;
  let str = "1111-253-asdasdas";
  let indexes = [];
  
  do {
      match = reg.exec(str);
      if (match) indexes.push(match.index);
  } while (match);
  </code></pre>
  
  <p>It works. It returns the indexes of all the characters that are numerical or alphabetical. But the problem is that if I try to make the opposite, with a negative lookahead in Regex, like this:</p>
  
  <pre><code>let match;
  let reg = /(?!([A-Za-z]|[0-9]))/g;
  let str = "1111-253-asdasdas";
  let indexes = [];
  
  do {
      match = reg.exec(str);
      if (match) indexes.push(match.index);
  } while (match);
  </code></pre>
  
  <p>It ends up in an infinite loop.</p>
  
  <p>What I'd like to achieve is the same result as in the first case, but with the negative regex, so in this case the result would be:</p>
  
  <pre><code>indexes = [4, 8]; // which are the indexes in which a non-alphanumerical character appears
  </code></pre>
  
  <p>Is the loop wrong, or it's the regex expression the one who is messing things up? Maybe the <code>exec</code> is not working with negative lookaheads Regex expressions?</p>
  
  <p>I would understand the regex expression not working as I intended to (because it may be wrongly formatted), but I don't understand the infinite loop, which leads me to think that <code>exec</code> maybe is not the best way to achieve what I'm looking for.</p>