Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda