Hacker News new | past | comments | ask | show | jobs | submit login

Btw it does some weird escaping for JavaScript string literals, also the regex was wrong:

  const htmlString = '<img src="image1.jpg" alt="Image 1"><img src="image2.jpg">';
 const regex = /<img\s[^>]*?src\s*=\s*['"]([^'"]+?)['"][^>]*?(?:alt\s*=\s*['"]([^'"]*?)['"])?[^>]*?>/gi;

  let match;
  while ((match = regex.exec(htmlString)) !== null) {
    const src = match[1];
    const alt = match[2] || null;
    console.log(`src: \${src}, alt: \${alt}`);
  }



Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: