I am working on a RegEX for a Quill editor and want to sanitize iframes. This code will take out the iframe, work fine.
Public Function RegexScriptTags(strValue)
Set RegularExpressionObject = New RegExp
With RegularExpressionObject
.Pattern = "<iframe[^><]*>.*?<.iframe[^><]*>
.IgnoreCase = True
.Global = True
End With
Dim strResult: strResult = RegularExpressionObject.Replace(strValue, " ")
Set RegularExpressionObject = Nothing
RegexScriptTags = strResult
End Function
First of all, I am using Classic ASP.
The issue that I have by using Quill is there is a way to embed youtube videos.
I want to continue to use that with Quill but the RegEX will remove it.
With Quill the iframe uses this class:
class="ql-video ql-align-center"
The align center was user inputted, but you can see what the class is.
So my question - Is there a way to do somewhat of a conditional RegEX that if the iframe was that specific class (or certain words), then ignore, else the iframe would be taken out?
I realize that this a .Net forum but I was thinking that there are some asp classic brainiacs out there.
(can probably be done better, but it works for me. Assert a negative lookahead that the word “youtube” does not occur before the end of the opening tag.)
It was code that I had, written by someone else. Honestly, I don’t understand the Regex’s. I am trying to sanitize for script tags and what you just gave me on iframes. All I know that along with yours, it works.
If you have a better way to do it, I would love to see it. And if you can explain it, I am always interested in having a better understanding of the symbols.
Thanks for what you have done. It’s appreciated.
Basically, just throw out all the <'s where you’re not looking for a literal <, and replace the .'s at the start of the end tags. Just for trimmin it up.