# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"<img src=\"(?<SRC>[^\"]+)\" width=\"(?<WIDTH>[^\"]*)\" alt=\"(?<ALT>[^\"]*)\" title=\"(?<TITLE>[^\"]*)\" \/>"
test_str = ("---\n"
"creation date: 2023-01-06 20:04\n"
"description: A test file\n"
"modification date: 2023-01-14 10:17\n"
"obsidianUIMode: source\n"
"tags:\n"
"- programming\n"
"---\n"
" \n"
"This is the child file \n"
" \n"
"# Embed2 \n"
" \n"
"Your modes, all markdown ones: \n"
"**1** <img src=\"001%20assets/AsexualPrideFlag.png\" width=\"100\" alt=\"The Asexual Flag\" title=\"The Asexual Flag\" /> \n"
"**2** <img src=\"001%20assets/AsexualPrideFlag.png\" width=\"100\" alt=\"\" title=\"\" /> \n"
"3 <img src=\"001%20assets/AsexualPrideFlag.svg\" width=\"100\" alt=\"The Asexual Flag\" title=\"The Asexual Flag\" /> \n"
"4 <img src=\"001%20assets/AsexualPrideFlag.svg\" width=\"100\" alt=\"The Asexual Flag\" title=\"The Asexual Flag\" /> \n"
" \n"
"// \n"
" \n"
"Wikilink-embeds: \n"
"**5**  \n"
"6  \n"
" \n"
"// \n"
" \n"
"Wikilink-embeds with names: \n"
"**7** <img src=\"001%20assets/AsexualPrideFlag.png\" width=\"\" alt=\"Asexual Pride Flag\" title=\"Asexual Pride Flag\" /> \n"
"8 <img src=\"001%20assets/AsexualPrideFlag.svg\" width=\"\" alt=\"Asexual Pride Flag\" title=\"Asexual Pride Flag\" /> \n"
" \n"
"// \n"
" \n"
"Wikilink-embeds with sizing \n"
"**9** <img src=\"001%20assets/AsexualPrideFlag.png\" width=\"100\" alt=\"\" title=\"\" /> \n"
"10 <img src=\"001%20assets/AsexualPrideFlag.svg\" width=\"100\" alt=\"\" title=\"\" /> \n"
" \n"
"// \n"
" \n"
"Wikilink-embeds with sizing and names \n"
"**11** <img src=\"001%20assets/AsexualPrideFlag.png\" width=\"100\" alt=\"Asexual Pride Flag\" title=\"Asexual Pride Flag\" /> \n"
"12 <img src=\"001%20assets/AsexualPrideFlag.svg\" width=\"100\" alt=\"Asexual Pride Flag\" title=\"Asexual Pride Flag\" /> \n"
" \n"
"// \n"
" \n"
"Markdown-embeds: \n"
"**13**  \n"
"14  \n"
" \n"
"// \n"
" \n"
"Markdown-embeds with names: \n"
"**15** <img src=\"001%20assets/AsexualPrideFlag.png\" width=\"100\" alt=\"Asexual Pride Flag\" title=\"Asexual Pride Flag\" /> \n"
"16 <img src=\"001%20assets/AsexualPrideFlag.svg\" width=\"100\" alt=\"Asexual Pride Flag\" title=\"Asexual Pride Flag\" /> \n"
" \n"
"// \n"
" \n"
"Markdown-embeds with sizing \n"
"**17** <img src=\"001%20assets/AsexualPrideFlag.png\" width=\"100\" alt=\"\" title=\"\" /> \n"
"18 <img src=\"001%20assets/AsexualPrideFlag.svg\" width=\"100\" alt=\"\" title=\"\" /> \n"
" \n"
"// \n"
" \n"
"Markdown-embeds with sizing and names \n"
"**19** <img src=\"001%20assets/AsexualPrideFlag.png\" width=\"100\" alt=\"Asexual Pride Flag\" title=\"Asexual Pride Flag\" /> \n"
"20 <img src=\"001%20assets/AsexualPrideFlag.svg\" width=\"100\" alt=\"Asexual Pride Flag\" title=\"Asexual Pride Flag\" /> \n"
" \n"
"All images with at **bolded numbers** are PNG's, all others SVG's. \n"
" \n"
"# EOF")
matches = re.finditer(regex, test_str)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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