Results 1 to 3 of 3

Thread: QRegExp - get only last result

  1. #1
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QRegExp - get only last result

    hello

    I wrote some code
    Qt Code:
    1. QRegExp reg("\\s*<h1 class=\"demot\">(\\d+)</h1>\\n");
    To copy to clipboard, switch view to plain text mode 

    this should parse a HTML file and find all text in the tag. And the problem is: I cannot get what I want. I wrote:
    Qt Code:
    1. int pos = 0;
    2.  
    3. while ((pos = reg.indexIn(result, pos)) != -1) {
    4. qDebug()<<result.mid(pos, pos + reg.matchedLength());
    5. pos += reg.matchedLength();
    6. }
    To copy to clipboard, switch view to plain text mode 
    but it doesn't work... What do I do wrong?

  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 - get only last result

    what does "\\s*" and "\\n" in your pattern. Also make yourself familiar with greedy and minimal matching. Then you probably find the problems

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QRegExp - get only last result

    \d+ will give you numbers and not text. And get yourself familiarized with QRegExp::cap(). But in general this is almost bound to fail. Either strip all the tags (which will leave you the text) or use QXmlQuery.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to display result
    By sksingh73 in forum Newbie
    Replies: 1
    Last Post: 7th June 2010, 08:39
  2. QSqlQuery return result
    By arpspatel in forum Qt Programming
    Replies: 2
    Last Post: 9th April 2010, 07:55
  3. QColorDialog always return 0 as a result
    By NoRulez in forum Qt Programming
    Replies: 8
    Last Post: 17th October 2009, 12:06
  4. Result of DBUS call
    By conexion2000 in forum Qt Programming
    Replies: 4
    Last Post: 28th July 2009, 08:34
  5. Wrong compiling result by QT!!??
    By greenoaktree in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2008, 13:36

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.