# If you'd like to omit non-matching lines from the result; add ';d' to the end of the expression.
sed -E 's/(?><p\s*>\s*(<img\s+(?:"[\S\s]*?"|'[\S\s]*?'|[^>]?)+\s*\\/?>)\s*<\\/p\s*>)|(?><(?:(?:(?:(script|style|object|embed|applet|noframes|noscript|noembed)(?:\s+(?>"[\S\s]*?"|'[\S\s]*?'|(?:(?!\\/>)[^>])?)+)?\s*>)[\S\s]*?<\\/\2\s*(?=>))|(?:\\/?[\w:]+\s*\\/?)|(?:[\w:]+\s+(?:"[\S\s]*?"|'[\S\s]*?'|[^>]?)+\s*\\/?)|\?[\S\s]*?\?|(?:!(?:(?:DOCTYPE[\S\s]*?)|(?:\[CDATA\[[\S\s]*?\]\])|(?:--[\S\s]*?--)|(?:ATTLIST[\S\s]*?)|(?:ENTITY[\S\s]*?)|(?:ELEMENT[\S\s]*?))))>)(*SKIP)(*FAIL)/$1/g;t' <<< "$example1 = '<p data-entity-type=\"\" data-entity-uuid=\"\" style=\"text-align: center;\"><span><img alt=\"image.jpg\" data-entity-type=\"\" data-entity-uuid=\"\" height=\"349\" src=\"image.jpg\" width=\"620\" /><span title=\"Click and drag to resize\">•</span></span></p>';
$example2 = '<p><img alt=\"image.jpg\" data-entity-type=\"\" data-entity-uuid=\"\" height=\"349\" src=\"image.jpg\" width=\"620\" /></p>';
$example3 = '<html>
<head></head>
<body>
some text here...
<p><img alt=\"image.jpg\" data-entity-type=\"\" data-entity-uuid=\"\" height=\"349\" src=\"image.jpg\" width=\"620\" />
</p>
</body>
</html>';
======================================
"
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 SED, please visit: https://www.gnu.org/software/sed/manual/html_node/The-_0022s_0022-Command.html