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

232
Vistas
how to extract url id from string with regex?

suppose that, i've this string:

google.com/:id/:category

how can i extract only id and category from this string?

i should use regex

this match doesn't work:

match(/\/:([a-zA-Z0-9]*)/g);

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You may try the following:

var url = "google.com/:id/:category";
var parts = url.match(/(?<=\/:)[a-zA-Z0-9]+/g);
console.log(parts);

This approach uses the positive lookbehind (?<=\/:) to get around the problem of matching the unwanted leading /: portion. Instead, this leading marker is asserted but not matched in the version above.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Well, capture groups are ignored in match with /g. You might go with matchAll like this:

const url = "google.com/:id/:category"
const info = [...url.matchAll(/\/:([a-zA-Z0-9]*)/g)].map(match => match[1])
console.log(info)

Credit: Better access to capturing groups (than String.prototype.match())

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