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

211
Visualizações
How would I replace a certain slash in a URL, if present in the URL, with different characters in JavaScript?

Vimeo seems to sometimes have URLs of the form https://vimeo.com/12345 and sometimes URLs with an extra backslash followed by a code, like https://vimeo.com/12345/6d789.

In the latter case, with the extra slash and value, that happens to differ from their embed code where the URL needs to look like https://vimeo.com/12345?h=6d789.

In my JavaScript, where I'm taking these URLs and creating embeds I need to replace the final / with ?h= but only if that final element is there. If it's like the first URL, with no extra / and value, I want to leave the final slash alone.

What might be a simple JavaScript expression that takes a Vimeo URL and does the correct replacement, but only if needed?

Thanks.

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

0

Here you go

let vimeoUrls = {
url1 : "https://vimeo.com/12345",
url2 : "https://vimeo.com/12345/6d789"
}

for(url of Object.values(vimeoUrls)){
if(url.split("/").length<5)
console.log(url) //return in production
let urlSplit = url.split("/")
if(url.split("/").length>4) //delete this line in production
console.log(`${urlSplit[0]}//
                    ${urlSplit[2]}/${urlSplit[3]}/? 
h=${urlSplit[4]}`)
 
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