using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?><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)";
string substitution = @"$1";
string input = @"$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>';
======================================
";
Regex regex = new Regex(pattern);
string result = regex.Replace(input, 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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx