[Solved] Problem with QRegExp
-
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
-
Yes it does.
QRegularExpression implements Perl-compatible regular expressions.
-
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 :)