Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Regular experssion match anything between <div> </div>

Last post 01-16-2008, 5:32 PM by Aussie Susan. 4 replies.
Sort Posts: Previous Next
  •  01-16-2008, 7:49 AM 38624

    Regular experssion match anything between <div> </div>

    Hi

    I am trying to write a expression in ASP that will match everything between div tag

    ReplacedString = RegularExpressionObject.Replace(body, news)

    The test file that i used contain:

    <div id="news"><tr>
    <td>somethign here</td>
    </tr></div>



    and news is HTML code

    I try a few expression but could find the pattern

    I have tried
    "(<div id=""news"">)((.)*)(</div>)" - Only work without new line

     I have tried that

    "(<div id=""news"">)((.*\n*)*)(</div>)"

    "(<div id=""news"">)((.*\n?)*)(</div>)"

    but when ever i run it then it take more then 5 mins and still not giving out any thing.

    Can you please show me how to do it please?Thanks a lot in advance.

  •  01-16-2008, 9:02 AM 38627 in reply to 38624

    Re: Regular experssion match anything between <div> </div>

    regEx.Pattern = "<div id=""news"">[\S\s]*?</div>"

    or less preferable:

    regEx.Pattern = "<div id=""news"">(?:.|\n)*?</div>"


  •  01-16-2008, 9:58 AM 38632 in reply to 38627

    Re: Regular experssion match anything between <div> </div>

    regEx.Pattern = "(?<=<div id=""news"">)[^<]+(?=</div>)"

     

     or contents of any div tag:

    regEx.Pattern = "(?<=<div[^>]*>)[^<]+(?=</div>)"

     

  •  01-16-2008, 10:28 AM 38635 in reply to 38632

    Re: Regular experssion match anything between <div> </div>

    glz, there's a few problems with those patterns, first of all the patterns assume no <> tags exist within the div (which is not the case), and Classic ASP does not support (?<=).


  •  01-16-2008, 5:32 PM 38666 in reply to 38635

    Re: Regular experssion match anything between <div> </div>

    Of course, if a <div> section can contain another one (or more) nested within it, then all bets are off and you will need to use some of the various 'balanced delimiter' techniques - if any are possible with 'classic ASP'!

    Susan 

View as RSS news feed in XML