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

185
Visualizações
Javascript get the value of an href after a certain pattern

I have a url like https://www.whatever.com/en-CA/something I want to capture anything that comes after the en-CA/ (the en-CA can be any combination of characters that have two letters, a dash, and two letters.

I am trying to use a regex to

  1. grab the window.location.href

  2. split the href at the pattern that matched the /en-CA/

  3. take the remainder of the href

    window.location.href.split(/^(\/[a-zA-Z]{2})(-)([a-zA-Z]{2}\/)$/[1].match(/.*/)
    

I dont think i quite have the right setup here. How do I accomplish grabbing everything after the /character character dash character character /

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

0

Here's my solution

const url = "https://www.whatever.com/en-CA/something";
const result = url.split(/\/[a-z]{2}-[a-z]{2}\//i)[1];

if (!result) throw new Error("Invalid url");

console.log(result);

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