in reply to Re^3: Regular Expression
in thread Regular Expression

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".

Replies are listed 'Best First'.
Re^5: Regular Expression
by ikegami (Patriarch) on Jun 28, 2005 at 19:38 UTC
    Mulitple closing body elements are illegal, so multiple closing body tags may not a problem. That problem is </body> could appear in a comment or in quotes.
Re^5: Regular Expression
by CountZero (Bishop) on Jun 28, 2005 at 19:54 UTC
    Nope, not rhetorical, just a trap!

    This is valid XHTML:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w +3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-ty +pe" /> <title>test</title> </head> <body/> </html>

    No </body> tag, so a naive regex breaks again.

    Of course you are right, the OP only wanted to match the <body> tag not the body-element.

    CountZero

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

      Funny you should mention that (we were discussing this with the <p> tag) - it's not valid because body isn't defined with an EMPTY content model (as is br, hr, etc.)

      w3c specs shown here
        Well, I'm not sure about that.

        The DTD of XHTML defines the <body>-tag as <!ELEMENT body %Block;> and %Block is further defined as

        <!ENTITY % block "p | %heading; | div | %lists; | %blocktext; | fieldset | table"> <!ENTITY % Block "(%block; | form | %misc;)*">

        Watch the * in the definition of %Block: zero or more times! So %Block can be empty, hence <body> can be empty and can be written as <body/>.

        Also the official validator at W3C says it is valid XHTML1.0

        CountZero

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