Results 1 to 6 of 6

Thread: regular expressions

  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default regular expressions

    I'm trying to match numbers in a row separated by a coma.
    Ex: 1,1,1,1,1,0,0,0,0,0,1

    If I use this "[0-9]," in the regexdialog Qt example, it works. But what if my row of numbers is: 12,123,1,1,0,0,12,0,0,0,1 ?
    How can I match any number that comes before a coma, and the last one?

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: regular expressions

    "[0-9]{1,3},*"

    Assuming your numbers always have between 1 and three digits.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: regular expressions

    or:
    [0-9]*,

  4. #4
    Join Date
    Sep 2010
    Posts
    45
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: regular expressions

    and:

    [\d]{1,3}\,{0,1}

    the sequence \d is equivalent to 0-9
    to match the comma we must write \,

    or
    ^[\d]{1,3}[\,]{0,1}

    http://doc.qt.nokia.com/4.7/qregexp.html
    Last edited by bred; 8th November 2010 at 14:52.

  5. #5
    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: regular expressions

    Or:
    \d+,

    If you wish to catch the last one as well then:
    \d+,?
    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.


  6. #6
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: regular expressions

    Thanks for the help. [0-9]{1,3} solves the problem.
    Last edited by been_1990; 8th November 2010 at 17:15.

Similar Threads

  1. Problem using SQLite3 with regular expressions
    By Yakuza_King in forum Qt Programming
    Replies: 2
    Last Post: 18th October 2010, 09:43
  2. Qt Application linked to regular dll.....
    By Programm3r in forum Qt Programming
    Replies: 7
    Last Post: 10th February 2010, 07:37
  3. Regular Expression Problem
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2009, 09:41
  4. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 01:25
  5. Qt regular expressions!!
    By notsonerdysunny in forum Qt Programming
    Replies: 9
    Last Post: 1st April 2007, 12:56

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.