fork download
  1. import re
  2. regex = r"```.*?```|`.*?`|(<img(?!.*?alt=(['\"]).*?\2)[^>]*)(>)"
  3. test_str = ("```html\n"
  4. "<img src=\"fil.png\">\n"
  5. "```\n\n"
  6. "- [ ] Here is another image <img src=\"fil.png\"> and another `<img src=\"fil.png\">`\n\n"
  7. " ```html\n"
  8. " <a href=\"scratch/index.html\" id=\"scratch\" data-original-title=\"\" title=\"\" aria-describedby=\"popover162945\">\n"
  9. " <div class=\"logo-wrapper\">\n"
  10. " </div>\n"
  11. " <div class=\"name\">\n"
  12. " <span>Scratch</span>\n"
  13. " </div>\n"
  14. " <img src=\"fil.png\">\n"
  15. " </a>\n"
  16. " ```")
  17.  
  18. matches = re.finditer(regex, test_str, re.DOTALL)
  19. for match in matches:
  20. if match.group(1):
  21. print ("Found at {start}-{end}: {group}".format(start = match.start(1), end = match.end(1), group = match.group(1)))
Success #stdin #stdout 0.02s 6852KB
stdin
Standard input is empty
stdout
Found at 61-79: <img src="fil.png"