Results 1 to 4 of 4

Thread: QRegExp and quantifiers

  1. #1
    Join Date
    Oct 2009
    Posts
    70

    Default QRegExp and quantifiers

    Hi,

    I've a QRegExp like this:

    Qt Code:
    1. ex.setPattern(".{" + QString("%1").arg(mMinLength) + "," + QString("%1").arg(mMaxLength) +"}");
    To copy to clipboard, switch view to plain text mode 

    where mMinLength and mMaxLength are the min and max length that I espected to have.

    I use this expression to validate both some QString from file and QString from QLineEdit.
    If the maxLenght is <= 1024 the QlineEdit works, insteand I can't input.

    Is there a limit to max number of quantifiers in QRegExp?

    How can avoid this?

    Many thanks

  2. #2
    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: QRegExp and quantifiers

    Quote Originally Posted by paolom View Post
    I use this expression to validate both some QString from file and QString from QLineEdit.
    1. for the QLineEdit validation, why not use the maxLength property instead?
    2. for the "string from file" validation why use a regexp at all if you only care about the size?
    Quote Originally Posted by paolom View Post
    Is there a limit to max number of quantifiers in QRegExp?
    I've never bothered to check before but apparently yes, although it is not mentioned in the docs. A quick look at the source tells us that quantifiers are bounded by "InftyRep" which appears to be set to 1025... To be honest I've not dug far enough to check how this constant impact quantifier bounds but its very existence is worrying as it would suggest that even a star quantifier is bounded to as little as 1024 repetition (not that I ever bumped into this but still...).
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Oct 2009
    Posts
    70

    Default Re: QRegExp and quantifiers

    Many thanks for your reply.

    I need to use this validator ( and not the maxLength ) cause I want to create a unique validator so I can validate a string from the line edit and a string that I read from a file.

    So, as your opinion, If I want to control an undefined string length ( > 1024 ) is there a suitable regular expression ??!! ( I think surely yes, but I'm not good with reg exp... )

  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: QRegExp and quantifiers

    Quote Originally Posted by paolom View Post
    I need to use this validator ( and not the maxLength ) cause I want to create a unique validator so I can validate a string from the line edit and a string that I read from a file.
    Subclass QValidator to check string length instead of using a QRegExpValidator

    Quote Originally Posted by paolom View Post
    So, as your opinion, If I want to control an undefined string length ( > 1024 ) is there a suitable regular expression ??!! ( I think surely yes, but I'm not good with reg exp... )
    Qt Code:
    1. QString s(".{%1, 1024}").arg(min);
    2. for (int i = 1; i < max / 1024 - 1; ++i) s += QString(".{0,1024}");
    3. s += QString(".{0,%2}").arg(max % 1024);
    To copy to clipboard, switch view to plain text mode 
    But, really, that is fugly...
    Last edited by fullmetalcoder; 20th December 2011 at 20:27.
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. Please help on QRegExp
    By lni in forum Qt Programming
    Replies: 6
    Last Post: 25th September 2011, 07:42
  2. QRegExp
    By tebessum in forum Qt Programming
    Replies: 1
    Last Post: 3rd August 2008, 18:44
  3. QRegExp help
    By Lele in forum Qt Programming
    Replies: 2
    Last Post: 8th February 2008, 10:07
  4. QRegExp
    By szczav in forum Qt Programming
    Replies: 4
    Last Post: 19th June 2007, 20:07
  5. QRegExp Help
    By Ahmad in forum Qt Programming
    Replies: 2
    Last Post: 28th May 2007, 00:13

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.