Results 1 to 5 of 5

Thread: Matching HTML tags

  1. #1
    Join Date
    Nov 2009
    Location
    Argentina
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Matching HTML tags

    Hi again!
    I need to match HTML tags (when one tag opens and when it closes). If I have
    Qt Code:
    1. <span class="css1">Some text</span>
    To copy to clipboard, switch view to plain text mode 
    It's very easy to match it. But I can't match them correctly when the following happens:
    Qt Code:
    1. <span style="font-weight: bold">So<span style="color:#F00">me</span> text</span>
    To copy to clipboard, switch view to plain text mode 
    The first opened tag matchs the first closed tag, not the last one.

    If someone can give me an example or tell me how to do it, I'll be really thanked.
    Thanks in advanced.
    I'm sorry for my poor English, I'm Argentinian

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Matching HTML tags

    If it is only one nested tag you could use something like:

    Qt Code:
    1. <[^>]+>([^<]*| NESTED )</[^>]+>
    To copy to clipboard, switch view to plain text mode 

    with NESTED like

    Qt Code:
    1. <[^>]+>[^<]*</[^>]+>
    To copy to clipboard, switch view to plain text mode 

    So you get:

    Qt Code:
    1. <[^>]+>([^<]*|<[^>]+>[^<]*</[^>]+>)</[^>]+>
    To copy to clipboard, switch view to plain text mode 

    But that approach is not very save...

  3. The following user says thank you to Lykurg for this useful post:

    pucara_faa (20th January 2010)

  4. #3
    Join Date
    Nov 2009
    Location
    Argentina
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Matching HTML tags

    Thank you very much for answering back!
    I'm getting on the right way with the code you gave me. But, I always capture the same expression. How can I match another expression?
    For example, in this string:
    Qt Code:
    1. <span style="font-weight: bold">So<span style="color:#F00">me</span> text</span>
    To copy to clipboard, switch view to plain text mode 
    I always match
    Qt Code:
    1. <span style="color:#F00">me</span>
    To copy to clipboard, switch view to plain text mode 
    What if I want to match the first tag (I'm sorry, I'm newbie with this)
    Again, thank you.

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Matching HTML tags

    I am not sure what you really want to achieve but to match also the whole just put brackets at the front and at the end: (PaternToMatch)

  6. #5
    Join Date
    Nov 2009
    Location
    Argentina
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Matching HTML tags

    And what if I have two or more nested tags?

Similar Threads

  1. no matching function error
    By arpspatel in forum Qt Programming
    Replies: 4
    Last Post: 16th October 2009, 15:47
  2. Html tags in QTreeView
    By 1111 in forum Qt Programming
    Replies: 1
    Last Post: 13th March 2009, 01:41
  3. QFontMetrics and HTML tags
    By vonCZ in forum Newbie
    Replies: 1
    Last Post: 14th August 2008, 12:13
  4. pattern [image] matching
    By rachana in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2007, 13:31
  5. Replies: 1
    Last Post: 17th March 2006, 08:01

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.