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

462
Vistas
How to Regular Expression to get all URL src in <Img> tag in JavaScript?

I have a Regular Expression for handle filter HTML string with JavaScript, i want to get all URL image from src attribute in <img> tag, but i want to support both charecters < > and &lt; &gt;. My sample code like below:

const filterImages = str => {
  const imgRegExp = /\&(?:quot|[gl]t);img.*?src="(.*?)"[^>]+>/g;
  const images = [];
    let img;
    while ((img = imgRegExp.exec(str))) {
      images.push(img[1]);
    }
  return images;
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I have come up with a bulky regex like this

(?:<img\s+src="(.*?)"[^.]*?\/?>|&lt;img\s+src="(.*?)"[^.]*?\/?&gt;)

I have tested it on a page's html and it seems fine https://regex101.com/r/zifqle/1

enter image description here

For convenience you could use named capturing groups, but it seems that they must be unique so the best I can think of is

(?:<img\s+src="(?<url1>.*?)"[^.]*?\/?>|&lt;img\s+src="(?<url2>.*?)"[^.]*?\/?&gt;)

Also try to include m (multiline) flag with the regex

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