I check name validity by this regular expression, allowing any symbol as suggested here:
// Allow any symbol
const QString validNameMatcher = QStringLiteral("^[a-zA-Z0-9 _.,!()+=`,\"@$#%*-]+$");
bool Class::isNameValid(const QString fileName)
{
QRegularExpression re(validNameMatcher);
QRegularExpressionMatch match = re.match(fileName);
if (match.hasMatch())
return true;
else
return false;
}
For a file name like 1111 Rick (wow) L50-57.stl
the above function returns true
. So far so good.
To allow diacritical marks, I just add [À-ž]
to the name-matcher as suggested here:
// [À-ž] is for diacritical marks
const QString validNameMatcher = QStringLiteral("^[a-zA-Z0-9À-ž _.,!()+=`,\"@$#%*-]+$");
After adding [À-ž]
, surprisingly, for the same file name of 1111 Rick (wow) L50-57.stl
, the above function returns false
. Am I missing something?
UPDATE
As suggested by @WiktorStribiżew , I used UseUnicodePropertiesOption
:
QRegularExpression re(validNameMatcher, QRegularExpression::PatternOption::UseUnicodePropertiesOption);
But it didn't work. The result is the same as before.
Also (*UTF)
doesn't work:
const QString validNameMatcher = QStringLiteral("(*UTF)^[a-zA-Z0-9À-ž _.,!()+=`,\"@$#%*-]+$");