import re
regex = re.compile(r"<td([^>]*)>\s*((?:.(?!</td>))+\s*)\s*<\?php audioButton\(\"([^\"]*)/.+?\",\".*?\"\);.*?\?>.*?</td>")
test_str = ("<td class=\"danish\">kat\n"
"<?php audioButton(\"../../audio/words/dog\",\"dog\");?></td>\n\n"
"<td class=\"danish\">kat\n"
"<?php audioButton(\"../../audio/words/dog\",\"dog\");?></td>\n\n"
"<td class=\"danish\">kat</td>\n"
"<td><?php audioButton(\"../../audio/words/dog\",\"dog\");?></td>\n\n"
"<td class=\"danish\">kat\n"
"<?php audioButton(\"../../audio/words/dog\",\"dog\");?></td>")
subst = "<td$1>$2<?php audioButton(\"$3/cat\", \"cat\");?></td>"
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