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}`); }
For some reason this seems to be trained deep into the GPT model. Even when you tell it in the prompt it doesn't exist sometimes it will contradict itself. That's why it can be an interesting test case