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

124
Visualizações
Negative Version of given regex needed (JS)

Again and again Regex... Can please someone show me how to got the negative lookahead working with the given regex here: https://regex101.com/r/kS6wUh/1

The Regex looks like this: ^\b[A-Z]+|_+?[A-Z]+

Target would be to check if a given string contains only Characters A-Z or _

Invalid_TEXT (invalid)
all_in_small_invalid (invalid)
INVALID-DASH (invalid)
VALID_KEY (valid)
ANOTHER_VALID_KEY (valid)
 (empty --> invalid)

The regex should match on invalid my current returns the valid matches.

I have no clue where to add (?!...) in my current version because all options I've tried ended up either by getting a regex error or counting everything. I think my regex has not the correct structure for a negative lookahead.

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

0

You only have to test if one or more characters in the string are not of the set [A-Z_], which is done by inserting a caret. So [^A-Z_]. Demo

const strs = `Invalid_TEXT
all_in_small_invalid
INVALID-DASH
VALID_KEY
ANOTHER_VALID_KEY
 (empty)`.split(`\n`);
 
strs.forEach(str => console.log(str, /[^A-Z_]/.test(str) ? `Not ok` : `OK`));
 

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