RegEx - finding the innermost block

Discussion in 'Perl Misc' started by msciwoj, Jul 16, 2009.

  1. msciwoj

    msciwoj Guest

    Does any one have an idea is it possible to catch the block that has
    no nested blocks of its type using regular expressions?
    In other words how to catch
    <blockbeginmark>.....-NO <blockbeginmark> until <blockendmark>

    For instance, can
    <div> ..... </div>
    block can be caught with the condition it has no nested <div> blocks
    in it?

    Any ideas?
     
    msciwoj, Jul 16, 2009
    #1
    1. Advertising

  2. On Jul 16, 7:51 am, msciwoj <> wrote:
    > Does any one have an idea is it possible to catch the block that has
    > no nested blocks of its type using regular expressions?
    > In other words how to catch
    > <blockbeginmark>.....-NO <blockbeginmark> until <blockendmark>
    >
    > For instance, can
    > <div> ..... </div>
    > block can be caught with the condition it has no nested <div> blocks
    > in it?
    >
    > Any ideas?


    Regular Expressions are not really good for context aware matching and
    parsing (which is what your match looks to be). For that, I would
    recommend you do a little search on CPAN for HTML parsing modules such
    as HTML::parser

    Cheers!
    --
    Donato Azevedo
     
    Donato Azevedo, Jul 16, 2009
    #2
    1. Advertising

  3. On Thu, 16 Jul 2009 03:51:05 -0700, msciwoj wrote:

    > Does any one have an idea is it possible to catch the block that has no
    > nested blocks of its type using regular expressions? In other words how
    > to catch
    > <blockbeginmark>.....-NO <blockbeginmark> until <blockendmark>
    >
    > For instance, can
    > <div> ..... </div>
    > block can be caught with the condition it has no nested <div> blocks in
    > it?


    Yes, use a html parser. There are many on CPAN and they work much better
    that any regex you can come up with.

    M4
     
    Martijn Lievaart, Jul 18, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Showjumper
    Replies:
    1
    Views:
    723
    Showjumper
    Mar 19, 2005
  2. =?Utf-8?B?Sm9obkRlSG9wZTM=?=

    Why Does Asp.Net Use The Innermost Exception?

    =?Utf-8?B?Sm9obkRlSG9wZTM=?=, Jul 14, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    592
    Karl Seguin [MVP]
    Jul 17, 2006
  3. morrell
    Replies:
    1
    Views:
    999
    roy axenov
    Oct 10, 2006
  4. Replies:
    3
    Views:
    822
    Reedick, Andrew
    Jul 1, 2008
  5. Replies:
    0
    Views:
    94
Loading...

Share This Page