Hi I have a free text editor for blog posts on my website with C# as code behind. I use the following regular expression to strip all HTML tags out of the post for security:
Regex.Replace(value, @"<(.|\n)*?>", string.Empty);
However I now have a requirement to allow the embedding of youtube videos, which use an iframe, for example:
<iframe width="425" height="349" src="http://www.youtube.com/embed/ttBhGiuMUmU" frameborder="0" allowfullscreen></iframe>
Could someone help me modify this regex to allow for this?
Try this one:
The
(?!/?iframe)is a negative lookahead, that checks that the<is not followed by aniframeor/iframe.I tested online here on regexr