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

71
Vistas
Regex pattern to replace a local address with a hyperlink address in javascript

I have a string

var str = "C:\Program Files\nodejs\node_modules"

I want to replace the "C:\Program Files\" part with a hyperlink part "https://" so that the final outcome is

"https://nodejs/node_modules"

The first step to replace the slases with regex I already did it with

replace(/\\\\/gi,"/")

hence it became

"C:/Program Files/nodejs/node_modules"

So, the regex for the final outcome ,am facing difficulties.

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

0

You might use 2 capture groups:

^[A-Z]+:\\(?:[^\\\n]*\\)*([^\\\n]+)\\([^\\\n]+)$
  • ^ Start of string
  • [A-Z]+:\\ Match 1+ chars A-Z : and \
  • (?:[^\\\n]*\\)* Optional repetitions of any char except \ ad then match \
  • ([^\\\n]+) Capture group 1 Match optional chars other than \
  • \\ Match \
  • ([^\\\n]+) Capture group 2 the same as for capture group 1
  • $ End of string

And replace with

https://$1/$2

See a regex demo.

const regex = /^[A-Z]:\\(?:[^\\\n]*\\)*([^\\\n]+)\\([^\\\n]+)$/gm;
const str = `C:\\Program Files\\nodejs\\node_modules`;
const result = str.replace(regex, `https://$1/$2`);
console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Find

^[A-Z]:\/[^\/]+(.*)

Replace

https:/$1
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