Results 1 to 2 of 2

Thread: need help with my regex

  1. #1
    Join Date
    Jan 2006
    Posts
    46
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default need help with my regex

    I have an process that outputs lines like that:
    0,0,1 some blah
    0,1,0 some blah
    1,0,1 some blah
    2,0,1 some blah

    I want to grab the first numeric part, this is how I do it:
    Qt Code:
    1. QString result = cdscanbus.readAllStandardOutput();
    2. qDebug()<< result;
    3. QRegExp rx("[0-9],[0-9],[0-9]");
    4. int pos = rx.indexIn(result);
    5. if(pos > -1){
    6. QString value = rx.cap(0);
    7. qDebug()<< value;
    8. }
    To copy to clipboard, switch view to plain text mode 

    the problem is that qDebug only returns the first 0,0,0 expression.
    any idea how to make it return all occurence of [0-9],[0-9],[0-9] ?
    thanx in advance

    Pat

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: need help with my regex

    There's an example in the docs:
    Qt Code:
    1. QString str = "offsets: 1.23 .50 71.00 6.00";
    2. QRegExp rx("\\d*\\.\\d+"); // primitive floating point matching
    3. int count = 0;
    4. int pos = 0;
    5. while ((pos = rx.indexIn(str, pos)) != -1) {
    6. ++count;
    7. pos += rx.matchedLength();
    8. }
    9. // pos will be 9, 14, 18 and finally 24; count will end up as 4
    To copy to clipboard, switch view to plain text mode 

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

    patcito (29th May 2006)

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.