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

242
Views
How do I write a regular expression that brings specific characters?

I want to extract a specific string from the inside when the following string exists. The string I want to extract is uuid.

But I don't know how to fill out the regular expression to bring uuid. How can I write it except for '/' and '-' before and after uuid?

const text = "hello_img/2021/12/27/uuid-c.jpg";
const reg = /\b\/u.*?-/g;
const matches = text.match(reg);
  
console.log(matches);

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Take text after last occurence of /, that seems to be th uuid that you want:

const url = "hello_img/2021/12/27/f189f4ae-af11-11e7-b252-186590cec0c1-helloworld.jpg";
console.log(url.split("/").pop());

output will be

f189f4ae-af11-11e7-b252-186590cec0c1-helloworld.jpg

to remove .jpg, you can use

newUrl = url.replace('.jpg','');
about 4 years ago · Juan Pablo Isaza Report

0

If you want to match the actual format of the uuid after the last occurrence of the / then you can match the / and capture the format in capture group 1 followed by matching any char except / till the end of the strin.

 \/\b([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\b[^\/\r\n]*$

Regex demo

const text = "hello_img/2021/12/27/f189f4ae-af11-11e7-b252-186590cec0c1-helloworld.jpg";
const reg = /\/\b([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\b[^\/\r\n]*$/;
const m = text.match(reg);
if (m) {
  console.log(m[1]);
}

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!