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

134
Vistas
Regex or alternative to strip string into variables to use in URL

I have something like this SW-763-20200622-XXX-YYY.

I need to create a URL link that has a static string + parts from the string above in a certain way - e.g. for this particular case https://www.static/SW/763/2020/06/22

So far I have something like this, that already shows static part + SW/763:

  <Link
    target="_blank"
    rel="noopener noreferrer"
    data-qa="link-report"
    href=
      {
      `https://www.static/${
        something.identifier.replace(/-/g, "/").slice(0, 6)}'
      }
  >
    Link
  </Link>

I played around with Regex and could also retrieve the year with /\d{4}(?=\d{4})/g but this approach means I would have to add to the current code, more lines with replace/regex to catch the year (with the regex I mentioned) and other(s) for the month/day also separated by / (20200622).

Wondering if there is a better way to do it either with a more complete regex or just a different approach.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You could capture the specific parts, and use the groups creating the expected format with replace.

^([A-Z]{2})-(\d{3})-(\d{4})(\d{2})(\d{2})\b.*

Regex demo

const regex = /^([A-Z]{2})-(\d{3})-(\d{4})(\d{2})(\d{2})\b.*/gm;
const s = `SW-763-20200622-XXX-YYY`;

console.log(s.replace(regex, `https://www.static/$1/$2/$3/$4/$5`))

about 4 years ago · Santiago Trujillo 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