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

240
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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