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

178
Visualizações
Check the end of string (regular expression)

i am trying to heck if a string (first argument, str) ends with the given target string (second argument, target). function confirmEnding(str, target) { return /target$/.test(str) } Test stringconfirmEnding("Bastian","n") show false. What i am doing wrong? Can i use regular expression as argument of function? ;

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

0

If it's always a string, then you can just use String#endsWith

function checkEnd(str, target) {
  return str.endsWith(target);
}

console.log(checkEnd("Bastion", "n"));

If you want to cast target into a regex, but note that this won't escape out any of the special characters in target. i.e. checkEnd('special)',')') will fail due to the regex being invalid:

function checkEnd(str, target) {
  return new RegExp(`${target}$`).test(str);
}

console.log(checkEnd("Bastion", "n"));

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