SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Sjoerd's Avatar
    Join Date
    Jun 2005
    Location
    Leimuiden, The Netherlands
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Matching all tags without closing tag

    I try to make a little regexp which can match all HTML tags from a string and outputs all tags which are not closed. This is what I got so far:

    Code:
    	html = "test <b>do not show this</b> blabla <p align='left' test2=sdf>haha hm <hr size=1>test";
    	tags = html.match(/<[^\/](([\w]*)[\w]*)[^>]*>(?!.*<[\/]\2>)/gi);
    	window.alert(tags);
    This code outputs all HTML tags, even if some of them are closed.

    It should check for text inside < and >, select the first word (which specifies the tag's name like IMG or HR) and then look if a </ tagname > version does NOT exist. If it doesn't exist, it should output the complete tag, like <img src="blaat.jpg">.

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not possible to parse html, xml etc with regular expressions.

  3. #3
    SitePoint Enthusiast Sjoerd's Avatar
    Join Date
    Jun 2005
    Location
    Leimuiden, The Netherlands
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's just a string with HTML tags, and it should only output an array which contains all matches (tags which do not have a closing tag) so I can't see why it cannot be possible?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •