Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!