ratojakuf
ratojakuf

Reputation: 738

Regual expression strange behavior

QRegExp regexpsplineedit("[a-zA-Z0-9\\_\\[\\]\\(\\)]{20}");
qlineedit->setValidator(new QRegExpValidator(regexpsplineedit,this));

This work.
And this not :

if(clipboardtext.contains(QRegExp("[a-zA-Z0-9\\_\\[\\]\\(\\)]{20}")))

But this yes :

if(clipboardtext.contains(QRegExp("[a-zA-Z0-9\\_\\[\\]\\(\\)]")) && clipboardtext.length() <= 20)

Why this happens with same text for input?

Upvotes: 0

Views: 53

Answers (1)

Armali
Armali

Reputation: 19395

Are you validating the length of the string is less than or equal to 20? Or that at least 1 char from that class exists and the total length is less than or equal to 20? That is 2 separate validation steps. Otherwise, its just ^[chars]{1,20}$ – sln

Upvotes: 1

Related Questions