in reply to How to tell if the content of one tag is completely contained within another?

Its not very clear what you are asking. If you want to know how to tell if the bold tags cover the fully content of the title tag maybe:

sub is_all_in_bold { my $title=shift; my ($title_content)=$title=~m!<title>(.*?)</title>!s; $title_content=~s!<b>.*?</b>!!sg; return !$title_content; } while (<DATA>) { print; chomp; print is_all_in_bold($_) ? "Its all in bold\n" : "Its not all in b +old\n"; } __END__ <title><b>Meta&hyphen;Ethics and The Problem of Creeping Minimalism</b +></title> <title>Meta&hyphen;Ethics and <b>The Problem of Creeping</b> <b>Minima +lism</b></title>

But i could have totally misunderstood the question.


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi

    Flux8


Replies are listed 'Best First'.
Re^2: matching
by Anonymous Monk on Oct 07, 2004 at 09:51 UTC
    That reports Its not all in bold on: <title><b>foo<b>bar</b></b></title>

      Yep and illustrates nicely why handling HTML with regexes is not recommended. Anyway, I think the following works:

      sub is_all_in_bold { my $title=shift; my ($title_content)=$title=~m!<title>(.*?)</title>!s; 1 while $title_content=~s#<b>(?:[^<>]+|(?!</?b>).)*</b>##s; print "$title_content\n"; return !$title_content; } while (<DATA>) { print; chomp; next unless /\S/; print is_all_in_bold($_) ? "Its all in bold\n" : "Its not all in b +old\n"; } __END__ <title><b>Meta&hyphen;Ethics and The Problem of Creeping Minimalism</b +></title> <title>Meta&hyphen;Ethics and <b>The Problem of Creeping</b> <b>Minima +lism</b></title> <title><b>foo<b>bar</b></b></title>

      ---
      demerphq

        First they ignore you, then they laugh at you, then they fight you, then you win.
        -- Gandhi

        Flux8