Results 1 to 4 of 4

Thread: QRegExp problem

  1. #1
    Join Date
    Feb 2010
    Posts
    53
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QRegExp problem

    I'm trying to get something recognised of the following format A1:Z9999 upper/lowercase (in other words in the range a1 to a9999 followed by a colon to Z9999). I tried using the regexp demo to try code out and my code seemed to work but putting it in my dialog box it doesn't.... Retrying it in the demo it doesn't either. Can any regexp guru's help? I've read the documentation but although its good none of the examples are near what I want to do.

    Qt Code:
    1. QRegExp regExp("A-Za-z][1-9][0-9][0-9]{0,3}[:][A-Za-z][1-9][0-9][0-9]{0,3}");
    2. //QRegExp regExp("[A-Za-z][1-9][0-9]{0,3}"); //works
    3. lineEdit->setValidator(new QRegExpValidator(regExp, this));
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QRegExp problem

    I'm not a regex guru but if the first line is your actual regex you are missing the opening bracket at the beginning of the string and you have an extra "[0-9]" before and after the colon. Using your commented out regex twice with a colon in between works for me in the demo.
    Qt Code:
    1. QRegExp regExp("[A-Za-z][1-9][0-9]{0,3}:[A-Za-z][1,9][0-9]{0,3}");
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2010
    Posts
    53
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QRegExp problem

    Thanks norobro I feel an idiot works fine with the missing bracket in. I stared that this code for hours today on and off and missed the missing start bracket. When I copied from the demo I must have missed it. That explains why it worked in the demo originally but not latterly. Just show you need someone to look at something you've done to see what you've missed.

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QRegExp problem

    You're welcome. I frequently do the same thing. You're right, it never hurts to have another set of eyes look at things.

Similar Threads

  1. Problem with QRegExp/C++
    By rte in forum Qt Programming
    Replies: 5
    Last Post: 5th September 2009, 08:52
  2. QRegExp
    By szczav in forum Qt Programming
    Replies: 4
    Last Post: 19th June 2007, 20:07
  3. QRegExp Help
    By Ahmad in forum Qt Programming
    Replies: 2
    Last Post: 28th May 2007, 00:13
  4. need help for my QRegExp
    By patcito in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2006, 16:29

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.