Results 1 to 4 of 4

Thread: QRegExp for extracting the string between two HTML tags...

  1. #1
    Join Date
    Jul 2008
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default QRegExp for extracting the string between two HTML tags...

    Greetings !

    Say i have <td>this is a test</td>... what would be the regexp pattern to get the string "this is a test" ?

    Thanks !

  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: QRegExp for extracting the string between two HTML tags...

    Since that is such an basic question, please use our Newbie section next time, and please read the documentation on regular expression. It don't have to be the Qt one. Any basic introduction on regular expressions. (http://www.regular-expressions.info/quickstart.html and grouping)

  3. #3
    Join Date
    Jul 2008
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QRegExp for extracting the string between two HTML tags...

    Sorry but i had my reasons to ask... I know regexp, no need to insult me.
    If i ask it's because normal regexp don't seam to be compatible with QRegExp.
    For my need, the following should work.
    (?<=<TH>)([a-zA-Z0-9 ])+(?=</TD>)

    Applied to <TH>test</TD> ... this pattern will return <TH>test... so the backward lookup doesn't seem to be implemented.

  4. #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: QRegExp for extracting the string between two HTML tags...

    Quote Originally Posted by tuthmosis View Post
    Sorry but i had my reasons to ask... I know regexp, no need to insult me.
    If i ask it's because normal regexp don't seam to be compatible with QRegExp.
    Well you didn't ask the following in the first time!
    For my need, the following should work.
    (?<=<TH>)([a-zA-Z0-9 ])+(?=</TD>)

    Applied to <TH>test</TD> ... this pattern will return <TH>test... so the backward lookup doesn't seem to be implemented.
    Yes, not all is implemented, but one can achieve all with some extra work.
    Qt Code:
    1. QString str = "<TH>test</TD> foo <TH>bar</TD>";
    2. QRegExp rx("<TH>([a-zA-Z0-9 ]+)</TD>");
    3. int pos = 0;
    4. while ((pos = rx.indexIn(str, pos)) != -1)
    5. {
    6. list << rx.cap(1);
    7. pos += rx.matchedLength();
    8. }
    9. qWarning() << list; // ("test", "bar")
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 6th December 2011, 22:44
  2. Matching HTML tags
    By pucara_faa in forum Qt Programming
    Replies: 4
    Last Post: 22nd January 2010, 13:19
  3. Html tags in QTreeView
    By 1111 in forum Qt Programming
    Replies: 1
    Last Post: 13th March 2009, 01:41
  4. QFontMetrics and HTML tags
    By vonCZ in forum Newbie
    Replies: 1
    Last Post: 14th August 2008, 12:13
  5. Replies: 1
    Last Post: 17th March 2006, 08:01

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.