[Solved] Problem with QRegExp
-
wrote on 18 Feb 2014, 13:38 last edited by
I am trying to use QRegExp to validate a string whether it only contains printable ASCII characters:
@QRegExp regex("(^[\\40-\\176]{1,47}$)");//Printable ASCII characters only
if(regex.exactMatch(value))
{
appName = value;
}@The problem is that the above Regular Expression (^[\40-\176]{1,47}$) is working as expected with "Expresso":http://www.codeproject.com/Articles/3669/Expresso-A-Tool-for-Building-and-Testing-Regular-E but not with QRegExp. I have also tested it with the .Net Regex class (System.Text.RegularExpression) and it works there, too. I'm not really familiar with QRegExp yet and hope someone might be able to help me.
cheers,
MarcoEdit: Thanks to SGaist who helped me solving my problem - The solution was to replace QRegExp with QRegularExpression, as described at "CodeProject":http://www.codeproject.com/Tips/729656/Reasons-to-abandon-and-replace-QRegExp-in-your-Qt
-
Hi and welcome to devnet,
To test/build your RegExps with Qt you have the QRegExp example in example/widgets/tools/regexp that can help
Also if you are using Qt 5 please consider moving to QRegularExpression
-
wrote on 18 Feb 2014, 15:46 last edited by
Dear SGaist,
thank you for your suggestion to move to QRegularExpression, it indeed fixed the issue. I did some reading on QRegExp and QRegularExpression - I assume QRegularExpression is using a better RegEx engine than QRegExp did?
-
Yes it does.
QRegularExpression implements Perl-compatible regular expressions.
-
wrote on 18 Feb 2014, 16:18 last edited by
Alright, thank you very much.
I did a quick writeup on my issue since I think that I'm not going to be the only one facing the very same issue.
Have "a look at it":http://www.codeproject.com/Tips/729656/Reasons-to-abandon-and-replace-QRegExp, if you want to. -
You're welcome !
Interesting article :)
Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)
-
wrote on 20 Feb 2014, 07:00 last edited by
The thread title is updated, and so is the question which now contains a small summary of the solution at its bottom.
4/7