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
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QRegExp Not Repeated More Than Four Times.

    Quote Originally Posted by mandlakoteswar2011 View Post
    QRegExp rx("^(?:[7-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9])$");
    If you are attempting to require that the first digit is 7-9, your regex is not correct as you have said zero or one (?) digit 7-9 is required. If you want to require that the regex matches a number that starts with 7-9 and has a max of 9 other digits 0-9, then the regex should be:
    Qt Code:
    1. QRegExp rx("^(?:[7-9][0-9]{1,9})$");
    To copy to clipboard, switch view to plain text mode 
    The above will match a digit between 7-9 followed by up to a minimum of 1 and maximum of 9 more digits 0-9. Additionally, since you're using a non-capturing group, which consists is the entire regex expression, you can likely just remove the grouping altogether.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  2. The following user says thank you to jefftee for this useful post:

    d_stranz (22nd September 2015)

  3. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,323
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QRegExp Not Repeated More Than Four Times.

    Additionally, since you're using a non-capturing group, which consists is the entire regex expression, you can likely just remove the grouping altogether.
    I thought about mentioning that as well as posting the simplified expression you gave. But since I have no idea what the OP was actually trying to match, I just left it alone.

    Perhaps the OP can respond with examples of what he does and does not want to match, then we can help with a better regex.

    Spent a lot of time years ago writing lex and yacc code to parse specialty "little languages" (as Jon Bentley calls them), so got pretty good at crafting regular expressions.
    Last edited by d_stranz; 22nd September 2015 at 20:39.

  4. #3
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QRegExp Not Repeated More Than Four Times.

    Quote Originally Posted by d_stranz View Post
    Spent a lot of time years ago writing lex and yacc code to parse specialty "little languages" (as Jon Bentley calls them), so got pretty good at crafting regular expressions.
    lex, yacc, regular expressions, and many other CS concepts are a black/lost art today for sure and as foreign to some as the courses I took way back in my undergrad days. Most of my CS background was theory based, data structures, algorithms, and of course programming language based, etc. Not sure what the CS curriculum in schools are all about nowadays, but I'm sure they're rife with the web languages of the day, HTML, CSS, etc.

    Often I find tortured uses for regular expressions when they're not really needed, or the opposite where a regex is a perfect solution that gets implemented in unmaintainable spaghetti code to parse stuff... The most valuable skill to have is to know when one is called for vs the other...
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

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.