Need Two Regular Expressions

Results 1 to 2 of 2

Thread: Need Two Regular Expressions

  1. #1
    Join Date
    Dec 1969

    Default Need Two Regular Expressions

    I am setting up a forum with a WYSIWYG post editor. It works fine for people with new browsers, however, people with older browsers are given a normal text box. The WYSIWYG editor works by submitting the HTML to the page, this means people with older browsers can send whatever HTML they want!<BR><BR>This is my plan. Replace all allowed HTML tags with a place holder, then replace all &#060;&#039;s with &_lt; (of course without the _) and all &#062;&#039;s with &_gt;, then replace the placeholders with HTML. I can do things such as bold, underline, lists, bullets, and a few others just fine. However, I need some help with links and images.<BR><BR>I, therefore, need two Regular Expressions. One that will catch links and one that will catch images. This is what I have for the link RegExp so far:<BR><BR>(http&#124ftp&#124https)://[w]+(.[w]+)([w-.,@?^=%&:/~+#]*[w-@?^=%&/~+#])?<BR><BR>It works fine, but i need one other thing. I do not want the user to input event handlers (onClick, onMouseOver, etc...) Can you guys help me with that?<BR><BR>Finally, the image one. I haven&#039;t got started on this one, because I have no idea where to start.<BR><BR>I need one that will allow things like this:<BR><BR>&#060;IMG src=""&#062;<BR><BR>But I want to allow properties such as alt, align, border, etc..<BR>Also, I want to make sure that the protocol of the src is either http,ftp, or https. Finally, I dont&#039; want to allow any event handlers.<BR><BR>If you guys could help me with any (or all :)) of these parts, I would be entirely grateful!<BR><BR>Thank you,<BR>Yohan

  2. #2
    Join Date
    Dec 1969

    Default RE: Need Two Regular Expressions

    &nbsp;<BR>Find any link:<BR><BR>&#060;a [^&#062;]*hrefs*=s*(&#039;&#124")?[^1]*1[^&#062;]*&#062;<BR><BR>Find any Image:<BR><BR>&#060;img [^&#062;]*srcs*=s*(&#039;&#124")?[^1]*1[^&#062;]*&#062;<BR><BR>Find an onclick event in the above link/image:<BR><BR>onclicks*=s*(&#039;&#124")?[^1]*1<BR><BR>Find multiple event handlers withing each link:<BR><BR>(onclick&#124onmouseover&#124onmouseo ut)s*=s*(&#039;&#124")?[^2]2<BR><BR>I&#039;m not sure exactly how you&#039;re going about your search and replace, but here are a few properties that might come in handy:<BR><BR>JScript: lastIndex, index (via exec())<BR><BR>VBScript: FirstIndex & Length (Match Object)<BR><BR>If VBScript doesn&#039;t support the 1, 2 notation, you should do this in JScript.<BR><BR>And you should certainly do this on the server-side, because older browser will have older versions of JavaScript, that will support fewer feature in their RegExp engine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts