import re
regex = re.compile(r"(<img.+?=\"Inv.+?\/)(.+?)(\.)(.+?)(class=\")(.+?)(.+?)(.+?\n)", flags=re.MULTILINE)
test_str = ("<img src=\"InviousAnim_assets/FLM_Image_1.png\" height=\"179px\" width=\"102px\" class=\"wlby_2\"></img>\n"
"<img src=\"InviousAnim_assets/FLM_Image_2.png\" height=\"55px\" width=\"144px\" class=\"wlby_2\"></img>\n"
"<img src=\"InviousAnim_assets/FLM_Image_3.png\" height=\"76px\" width=\"76px\" class=\"wlby_2\"></img>\n"
"<img src=\"InviousAnim_assets/FLM_Image_4.png\" height=\"142px\" width=\"123px\" class=\"wlby_2\"></img>\n"
"<img src=\"InviousAnim_assets/FLM_Image_5.png\" height=\"109px\" width=\"109px\" class=\"wlby_2\"></img>\n"
"<img src=\"InviousAnim_assets/FLM_Image_6.png\" height=\"73px\" width=\"70px\" class=\"wlby_2\"></img>\n"
"<img src=\"InviousAnim_assets/FLM_Image_7.png\" height=\"98px\" width=\"97px\" class=\"wlby_2\"></img>\n"
"<img src=\"InviousAnim_assets/FLM_Image_8.png\" height=\"109px\" width=\"109px\" class=\"wlby_2\"></img>\n"
"<img src=\"InviousAnim_assets/FLM_Image_9.png\" height=\"73px\" width=\"70px\" class=\"wlby_2\"></img>")
subst = "\\1\\2\\3\\4\\id=\"\\2\"/>\\n"
result = regex.sub(subst, test_str)
if result:
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html