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

137
Visualizações
Want to write regex in javascript which will check if all the mentioned chars exist at least ones

I have string s and need to check if that string contains every single alphabet from a to z. What will the regex be to check this condition? where s can be very big string with multiple words separated with space.

ex:

pattern.test("zy aemnofgbc jkhil pqasdfrs tuvrhfwx") 

should return true as it contains all a-z alphabets at least ones.

pattern.test("sdfasbcd effsdgh ijsfghtkl mnhtop qrsjht uvwmnmx yfdhjkd") 

should return false as it doesn't have alphabet z.

Looking for optimum solution.

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

0

the easiest way is by extracting unique chars

function testAlphabet(str) {
  var chars = str.replace(/[^a-z]/g).split(''); // it may need to convert to lowercase
  // remove duplicate
  chars = [...new Set(chars)];
  console.log(chars.join('').length == 26)
}

testAlphabet("zy aemnofgbc jkhil pqasdfrs tuvrhfwx")

testAlphabet("sdfasbcd effsdgh ijsfghtkl mnhtop qrsjht uvwmnmx yfdhjkd")

about 4 years ago · Juan Pablo Isaza Relatório

0

First solution with regex - removes all non-alphabetic characters, duplicates, and compares the string length with 26.

Second solution without regex, just checks is every alphabetic characters in string.

const test1 = (str) => str.replace(/[^a-z]|(.)(?=.*\1)/gi, '').length === 26;

const test2 = (str) => [...`abcdefghijklmnopqrstuvwxyz`]
  .every(ch => str.includes(ch));


console.log(test1('zy aemnofgbc jkhil pqasdfrs tuvrhfwx'));
console.log(test1('y aemnofgbc jkhil pqasdfrs tuvrhfwx'));

console.log(test2('zy aemnofgbc jkhil pqasdfrs tuvrhfwx'));
console.log(test2('y aemnofgbc jkhil pqasdfrs tuvrhfwx'));
.as-console-wrapper{min-height: 100%!important; top: 0}

about 4 years ago · Juan Pablo Isaza Relatório

0

Is all a-z

function isAllaz() {
  let s = "zy aemnofgbc jkhil pqasdfrs tuvrhfwx";
  //console.log([...new Set(s.split("").filter(e => e.match(/[a-z]/)))].length==26);
  return [...new Set(s.split("").filter(e => e.match(/[a-z]/)))].length==26;
}
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