PDA

View Full Version : QRegExp problem



hollowhead
4th May 2010, 16:37
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.




QRegExp regExp("A-Za-z][1-9][0-9][0-9]{0,3}[:][A-Za-z][1-9][0-9][0-9]{0,3}");
//QRegExp regExp("[A-Za-z][1-9][0-9]{0,3}"); //works
lineEdit->setValidator(new QRegExpValidator(regExp, this));

norobro
4th May 2010, 19:27
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.
QRegExp regExp("[A-Za-z][1-9][0-9]{0,3}:[A-Za-z][1,9][0-9]{0,3}");

hollowhead
4th May 2010, 20:33
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.

norobro
4th May 2010, 20:49
You're welcome. I frequently do the same thing. You're right, it never hurts to have another set of eyes look at things.