Results 1 to 3 of 3

Thread: QRegExpValidator - help with regex for matching "1, 2, 3, 4-10, 20+"

  1. #1
    Join Date
    Mar 2012
    Posts
    5

    Default QRegExpValidator - help with regex for matching "1, 2, 3, 4-10, 20+"

    Hi,

    I need to limit the accepted inputs for a QLineEdit with a QRegExpValidator - but since I am not very familiar with RegExp, I am a bit confused how the RegExp I need would look like..

    The Input can be a:

    - A single number (eg. "1")
    - A range (eg. "10-20")
    - A infinite range (eg "10+" or "10-")
    - Any combination of these comma-separated (eg "1, 2, 5, 10-30, 50+")

    It is not important if the numbers in a comma-separated list make sense or are ascending, this would also be valid "5,2,13,4-20,3+,200-300,50-"

    Any idea how I would do this with QRegExpValidator? Or any other nice solution?

    Thanks,
    Kira

  2. #2
    Join Date
    Apr 2007
    Location
    Ilsfeld, Germany
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QRegExpValidator - help with regex for matching "1, 2, 3, 4-10, 20+"

    Hi,

    ((\d+-\d+)|(\d+[+-]?)) should match one item r.

    r(, *r)* should match a list of these items. Try:

    Qt Code:
    1. QRegExp re("^((\\d+-\\d+)|(\\d+[+-]?))(, *((\\d+-\\d+)|(\\d+[+-]?)))*$");
    To copy to clipboard, switch view to plain text mode 
    HTH, Bernd

  3. #3
    Join Date
    Sep 2011
    Location
    Portugal
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QRegExpValidator - help with regex for matching "1, 2, 3, 4-10, 20+"

    http://regexpal.com/ is your friend
    There's a quick reference that might help you there.

Similar Threads

  1. Replies: 1
    Last Post: 7th April 2010, 21:46
  2. Replies: 3
    Last Post: 15th February 2010, 17:27
  3. Replies: 3
    Last Post: 8th July 2008, 19:37
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

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.