Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

validate strings separated by dot (.) in QT

Tags:

regex

qt

qt4

Can any one suggest me how to validate strings separated by dot (.) in QT basically just like package name in java,

My code goes like this

QRegExp rx("^[\\w]+[^\\.{0,1}\\w+$]*$");
rx.setCaseSensitivity(Qt::CaseInsensitive);
return rx.exactMatch(package);

but I am getting wrong results

Ex:

 com.me.test // valid
 com.me.he. // invalid
 .com.me.he // invalid
 com..me.me // invalid
like image 915
Sharanabasu Angadi Avatar asked Feb 18 '23 19:02

Sharanabasu Angadi


1 Answers

Thats because of your wrong use of a character class. Characters that are between square brackets are a character class, so

 [^\\.{0,1}\\w+$]*

is a negated character class, because it starts with a ^. This class will match any character that is not one of those characters: ".{},01+$" or that is not in \w.

What you want sounds more like

^\\w+(\\.\\w+)*$

See it here on Regexr

And by the way, you don't need the CaseInsensitive option, because you don't have explicitly written letters in your regex.

like image 97
stema Avatar answered Feb 26 '23 22:02

stema