Quill editior Regex for iframes

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.

Thank you and appreciate your help.

Well your pattern’s missing a closing quote, for starters…

<iframe(?![^>]*youtube[^>]*>)[^><]*>.*?<.iframe[^><]*>

(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.)

1 Like

Yes, I see that. My fault in that I was using an or operator and didn’t close it when pasting. Thanks

Works for me too!! Well done and thanks for being one of those brainiacs out there!
I really appreciate it and thank you so much.

1 Like

Would like your opinion. Is it okay to use this as an or |

.Pattern = "<script[^><]*>.*?<.script[^><]*>|<iframe(?![^>]*youtube[^>]*>)[^><]*>.*?<.iframe[^><]*>"

Because I wasn’t sure if you can have different patterns, like this in the same regex code (2 patterns after each other).

.Pattern = "<script[^><]*>.*?<.script[^><]*>"
.Pattern = "<iframe(?![^>]*youtube[^>]*>)[^><]*>.*?<.iframe[^><]*>"

Appreciate knowing what is best to do. Thanks

Well why are you using a . to match the /in an end tag?

Why are you searching for <'s inside of the open tag? how often are you finding tags inside tags?

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.

Well the symbols are simple enough to explain. It’s the logic that baffles me.

. means “any character”
[^><] means “any character that is NOT a > or a <”

Why the original author thinks you’d run into another < inside of a tag is baffling to me…
<div thing="skdka" <img tag for no reason> endmydiv>

And this:
<.script
would match </script, but it would also match <ascript or <jscript or…

Best answer I can give you is that I don’t know. I don’t understand the logic at all.

To clarify, you gave me this below. Is this correct?

`<iframe(?![^>]*youtube[^>]*>)[^><]*>.*?<.iframe[^><]*>`

and how would you change this so the logic is correct?

<script[^><]*>.*?<.script[^><]*>

Thanks

<script[^>]*>.*?</script[^>]*>

<iframe(?![^>]*youtube[^>]*>)[^>]*>.*?</iframe[^>]*>

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.

1 Like

Thanks!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.