#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0

    Match HTML tags with specified attributes?


    Hello there,
    I'm a newbie with Regex so I'm confused about how to match HTML opening tags with specified attributes. Eg I want to match "div" elements that have those attributes only : style, class, id. If at least one of the attributes is not found or other attributes appear then the tags will not be matched. Anyone could help me please? Thanks so much.
    I'm using PHP.
  2. #2
  3. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    938
    Not really a task for regex. A parser is far less error prone: http://simplehtmldom.sourceforge.net/
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    I agree - you do not want to parse HTML or XML with regex - that way lies madness. There are lots of alternative ways of getting data from HTML/XML files such as DOM parsers, SAX parsers and xpath. If your language does not support any of them then you are using the wrong language.

    Dave

IMN logo majestic logo threadwatch logo seochat tools logo