RegExp and Replace On Load

I have a bulletin board system that I use Regular Expressions (in .NET) to prevent use of HTML and allow for certain BBCode tags to be used in place of HTML.  I want to have a preview pane that they click a button and a new window opens with a preview of what their post would look like.  The only problem is that I can't get my javascript RegExp's to work properly.  I need help in debugging this to fire with the onload attribute of the preview page.

Code:
<script language="javascript" type="text/javascript">
      function myPreview() {
            var vbCrLf = Chr(13) + Chr(10);
            var myHTML = window.opener.document.getElementById("Comment").value;
            myHTML = myHTML.replace(vbCrLf, "<br>");
            var re1 = new RegExp(<\/?[^>]*>, "g");
            if (myHTML.match(re1)) {
                  myHTML = myHTML.replace(re1, "");
            }
            var re2 = new RegExp(\[(\/?[a-zA-Z]?([0-9]?))\], "g");
            if (myHTML.match(re2)) {
                  myHTML = myHTML.replace(re2, "<$1>");
            }
            var re3 = new RegExp(\[url\=((.|\n)*?)\]((.|\n)*?)\[/url\], "g");
            if (myHTML.match(re3)) {
                  myHTML = myHTML.replace(re3, "<a href=$1 target=_blank>$3</a>");
            }
            var re4 = new RegExp(\[url\]((.|\n)*?)\[/url\], "g");
            if (myHTML.match(re4)) {
                  myHTML = myHTML.replace(re4, "<a href=$1 target=_blank>$1</a>");
            }
            document.getElementById("divPreview").innerHTML = myHTML;
      }
</script>
</head>
<body onload="myPreview();">

I know that the actual RegExp's work as they should, it's just that I can't get the code to replace them when the page loads.  What do I do?
LVL 5
jpontaniAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZvonkoSystems architectCommented:
What error do you get?
Is the value from "Comment" unchanged or do you get no value?

0
mr_egyptianCommented:
I think you're getting your VB and JS mixed a bit. This seems to work:


<html>
 <head>
  <title></title>
<script language="javascript" type="text/javascript">
     function myPreview() {
          var vbCrLf = String.fromCharCode(13) + String.fromCharCode(10);
          var myHTML = window.opener.document.getElementById("Comment").value;
          myHTML = myHTML.replace(vbCrLf, "<br>");
          var re1 = new RegExp(/<\/?[^>]*>/);
          if (myHTML.match(re1)) {
               myHTML = myHTML.replace(re1, "");
          }
          var re2 = new RegExp(/\[(\/?[a-zA-Z]?([0-9]?))\]/);
          if (myHTML.match(re2)) {
               myHTML = myHTML.replace(re2, "<$1>");
          }
          var re3 = new RegExp(/\[url\=((.|\n)*?)\]((.|\n)*?)\[\/url\]/);
          if (myHTML.match(re3)) {
               myHTML = myHTML.replace(re3, "<a href=$1 target=_blank>$3</a>");
          }
          var re4 = new RegExp(/\[url\]((.|\n)*?)\[\/url\]/);
          if (myHTML.match(re4)) {
               myHTML = myHTML.replace(re4, "<a href=$1 target=_blank>$1</a>");
          }
          document.getElementById("divPreview").innerHTML = myHTML;
     }
</script>
</head>
<body onload="myPreview();">
<div name="divPreview" id="divPreview"></div>
</body>
</html>


You need to delimit your expressions, and the escape any instance of the delimiter. There is no 'chr' datatype in JS. Hope that helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mr_egyptianCommented:
BTW

It may be a better design to modify your asp page to create the preview. The code is already there anyway.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.