Results 1 to 9 of 9

Thread: QRegExp Not Repeated More Than Four Times.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: QRegExp Not Repeated More Than Four Times.

    Quote Originally Posted by mandlakoteswar2011 View Post
    The Above Experisson it Wont Take "2"'s more than four times.
    As Chris67 said: your expression accecpts up to 9 digits after the first.
    If you only want to accept 4, then don't add the remaining 5 options.

    Cheers,
    _

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,349
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: QRegExp Not Repeated More Than Four Times.

    QRegExp rx("^(?:[7-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9])$");
    As I read your regular expression, it says:

    Match:
    • from the start of the string ("^")
    • the sub-expression: ("(?:")
    • zero or one of 7, 8, or 9 ("[7-9]?")
    • followed by zero or one of 0 through 9, up to eight times ("[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?")
    • followed by a single digit 0 through 9 ("[0-9]")
    • and this must be the entire string (")$")


    So your regex will match the following:

    • Any string containing only a single digit 0 - 9 (including strings containing only "7", "8", or "9")
    • Any string starting with 7, 8, or 9 and ending with any single digit 0 - 9
    • Any string starting with 7, 8, or 9 followed by up to eight more digits 0 - 9, ending with one more 0 - 9
    • Any string containing one through nine digits between 0 and 9


    For example:

    • "0" (or "1", "2", ... "9")
    • "70" (or "71", "72", ... "99")
    • "70" (or "701", "7012", "7013", ... "7012345678")
    • "0" (or "01", "012", "0123", ... "012345678"


    Note that it will not match "7 22222 222" since this contains embedded whitespace. It will match "722222222".

    Edit: So, your regex will match any string of one through eight digits between "0" and "99999999" and also any string of one through nine digits that starts with a "7", "8", or "9".
    Last edited by d_stranz; 21st September 2015 at 18:27.

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

    anda_skoa (22nd September 2015)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: QRegExp Not Repeated More Than Four Times.

    Nice explanation d_stranz. Way more effort than I put in (no way i was going type type that on my tablet ). I hope it is not lost on the OP.

  5. The following user says thank you to ChrisW67 for this useful post:

    d_stranz (22nd September 2015)

Similar Threads

  1. Replies: 0
    Last Post: 2nd April 2013, 19:26
  2. Replies: 0
    Last Post: 2nd April 2013, 10:48
  3. Animation problems, after repeated calls to start
    By pan in forum Qt Programming
    Replies: 2
    Last Post: 11th March 2011, 12:27
  4. QTabWidget currentChanged signal for repeated selects of a tab
    By balasaravanan in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2011, 06:04
  5. Replies: 1
    Last Post: 3rd August 2009, 12:44

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
  •  
Qt is a trademark of The Qt Company.