in reply to Regular Expression

Unfortunately for my purpose I cannot use that module :-) I need to use strict regex

Replies are listed 'Best First'.
Re^2: Regular Expression
by CountZero (Bishop) on Jun 28, 2005 at 19:21 UTC
    Homework? Or some fundamental religious rule which forbids you to handle HTML other than with a regex?

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      ROTFL.


      -Waswas
Re^2: Regular Expression
by Transient (Hermit) on Jun 28, 2005 at 19:17 UTC
    <flame suit on>
    $html =~ /(<body[^>]+>)/s;

    $html =~ /(<body[^>]*>)/s;
    that should get you the opening tag.

    Update: Changed + to * as pointed out by kwaping
      That'll fail for <body onload="if (a > b) { ... }">. It can also fail if <body> is found in comments.
        See Re: Regular Expression (the bottom regexp) - although to be fair, it should probably check for single quotes, too...
      And how do you find the closing tag?

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

        Even though I believe this is a rhetorical question...
        m!</body>!
        Yes.. with multiple closing body tags, it will be icky - yes, enclosed in comments it will be double super secret fudgy icky. But the OP wants a regexp to find the tag (and actually didn't even ask about the closing tag!), so like Burger King, "Have it Your Way".
        The OP didn't ask for that. He asked to match the opening tag, no matter what it had for attributes.