Results 1 to 4 of 4

Thread: Quick RegExp question

  1. #1
    Join Date
    Jun 2007
    Posts
    10
    Thanks
    3

    Default Quick RegExp question

    I'm using QRegExp and I want to parse resolution strings for the width and height.

    IE "640x480" should be parsed into two strings "640" and "480".

    I thought I could do this with capturedTexts(), but it works differently than I expected. Anyways, there must be an easy way to do this and I'm just not seeing it.

    This is what I wrote, which after reading the documentation will not of course do what I was hoping.

    Qt Code:
    1. QRegExp RegExp( "\\d+" );
    2. QStringList StringList;
    3.  
    4. RegExp.indexIn( strResolution );
    5.  
    6. StringList = RegExp.capturedTexts();
    To copy to clipboard, switch view to plain text mode 

  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: Quick RegExp question

    Quote Originally Posted by stealth86 View Post
    Qt Code:
    1. QRegExp RegExp( "\\d+" );
    To copy to clipboard, switch view to plain text mode 
    Do you have forgot the brackets?
    Qt Code:
    1. QRegExp RegExp( "(\\d+)" );
    To copy to clipboard, switch view to plain text mode 

    Lykurg

  3. #3
    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: Quick RegExp question

    Try:
    Qt Code:
    1. QRegExp RegExp( "(\\d+)x(\\d+)" );
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Quick RegExp question

    if your input is as simple as "width"x"height" then just use QString::split() it's both safer (no way the function fails if the delimiter is correct), simpler and faster.
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. Quick Question on QSqlQuerry
    By locus in forum Qt Programming
    Replies: 1
    Last Post: 13th March 2007, 14:53
  2. Quick spacing question
    By bruccutler in forum Newbie
    Replies: 4
    Last Post: 8th March 2007, 20:46
  3. Quick question regarding abstract classes and DLLs
    By durbrak in forum Qt Programming
    Replies: 1
    Last Post: 8th February 2007, 21:32
  4. quick question on model/view programming
    By locus in forum Qt Programming
    Replies: 1
    Last Post: 2nd February 2007, 10:04

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.