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

148
Visualizações
How do I build a Regexp that doesn't care about positions

I'm making a Scrabble game with HTML and Javascript and I'd like to add a "hint word" feature based on the player's rack. I have a dictionary array with the valid words, and I need to test them against the players available tiles but I couldn't figure out how to do a regexp that gives me the following output:

Lets say the player has D-G-O-G-I-*-E tiles and the Regexp should return:

doggies = True (because of the wildcard) gore = True dog = True god = true dodge = false (because D appears only once)

It doesn't matter the order, only the letters and the times that letter is repeated

I've already tried building it with the valid letters like this /[DGOGIE]/ in regexpal.com but it didn't work at all I also tried playing with this (?=.*a)(?=.*b)(?=.*c) but still no result

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

0

I'm not quite sure how you would do this with regex, but here is the solution that @Felix described:

function check(letters, wordToCheck) {
    for (char of wordToCheck) {
        if (letters.split(char).length - 1 < wordToCheck.split(char).length - 1) {
            return false;
        }
    }
    return true;
}

console.log(check("dgogyefi", "doggie"));
console.log(check("gepdoi", "doggie"));

(Sorry if I answered too late)

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