Discussion in 'Perl Misc' started by Lee, Nov 19, 2006.

  1. Lee

    Lee Guest

    I have this template file that I am opening in my script.


    <td>Name: {name3}</td>
    <td>Age: {age3}</td>


    Are there any good regular expressions to grab each tag and its
    contents? I'm doing this in javascript, but I'm guessing that there
    are some really good regex experts in this group.
    If there are any perl, php, or javascript libraries out there for this
    sort of thing, I'd like to know about it!
    Lee, Nov 19, 2006
    1. Advertisements

  2. Lee

    Henry Law Guest

    General advice here is not to try to parse HTML or XML with regexes;
    it's a great deal harder than it looks and there are much better ways to
    do it.
    Here's one: http://search.cpan.org/search?query=parse+html&mode=all

    And another you might find useful, in the context of your post:
    Henry Law, Nov 19, 2006
    1. Advertisements

  3. No. But here is a bad one that grabs the contents of all tags
    in _your_ data (it can be easily broken by other legal HTML data though):

    foreach my $tag ( /(<[^>]+>)/g ) {
    print "$tag\n";

    But I expect you don't really want what you've asked for, you
    probably want the contents of *element* rather than tags. For
    that you should...

    .... use a module that understands HTML data when you need to
    process HTML data:

    Tad McClellan, Nov 20, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.