Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
Regex for "must contain a character outside of this range"?

Is there a regex syntax equivalent to "must contain a character outside of this given range"?

For instance, if I want to match any string that contains a character which is not any of these: 1,a,@

...but can also contain the characters in the range?

Examples:

1111 - Would not match

11a@ - Would not match

1a@b - Would match

cdef - Would match

I thought perhaps (?=.*[^1a@]) would do the trick, but no dice.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Instead of using a lookahead, you could match at least a single occurrence of [^1a@] in the string.

Note that [^1a@] can also match a newline or a space.

^.*?[^1a@\r\n].*$

See a regex demo.

If you don't want to match only spaces, you use \s in the negated character class [^1a@\s] to exclude a whitspace char only being a valid match.

Example getting the whole match:

const regex = /^.*?[^1a@\r\n].*$/;
["1111", "11a@", "1a@b", "cdef"].forEach(s => {

  const m = s.match(regex);
  if (m) {
    console.log(s)
  }

});

Example testing if the string contains any char other than the listed in the character class:

["1111", "11a@", "1a@b", "cdef"].forEach((s) => {
  if (/[^1a@]/.test(s)) {
    console.log(s);
  }
});

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda