0

Consider:

    <% 
        content = ""+Request.Form("completehtml")+"";
        contentmatch = content;
        contentmatch = contentmatch.match(/(<div class="content">[\s\S]+?)(?=[##])/ig); 
    %>

If I get the above match and it gives me some HTML: is it possible to find text in the match and to replace it again?

    contentmatch = contentmatch.replace(/test/ig, 'working');

The problem I get with the replace is, that Internet Explorer says it is not supported. What is the reason?

    <% 
        content = ""+Request.Form("completehtml")+"";
        contentmatch = content;
        contentmatch = contentmatch.replace(/>\s+?</ig, '><'); 
        contentmatch = contentmatch.match(/(<div class="content">[\s\S]+?)(?=[##])/ig); 
    %>

OK it seems like I figured it out partly - If you do the replace before the match it seems to work, if you do it after the match is does not seem to work.

Is it possible to do a replace after the match?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gerald Ferreira
  • 1,349
  • 2
  • 23
  • 44
  • 3
    Reg3x cann0t pärse HtM|_: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – Mark Byers Jan 05 '10 at 19:46
  • "The problem I get with the replace is, that IE says it is not supported?" --> IS THAT WORKS WITH MOZILLA FIREFOX ??? – Michel Gokan Khan Jan 05 '10 at 19:55
  • Mark Byers - Nice one :-) but it can parse simple html if you are sure the code validates if

    is always going to be

    you can parse it - I think the trick is not to parse complicated html that does not validate.... but I am using the regex on my own stuff which is not over complicated and always validates...
    – Gerald Ferreira Jan 05 '10 at 20:08

1 Answers1

0

Your line:

contentmatch = contentmatch.match(/(<div class="content">[\s\S]+?)(?=[##])/ig);

is replacing the contentmatch variable with the result of the match method. That result is an Array. Arrays do happen to have a replace method (in FF), but it does something different than the String method, which is what you want.

jhurshman
  • 5,861
  • 2
  • 26
  • 16