Mr. Developerdude
Mr. Developerdude

Reputation: 9668

Handling accented letters in QRegularExpressions in Qt5

I am accepting input for the full name of the user using QLineEdit, and I want to accept

all international characters

such as "é" in French or "æ", "ø", and "å" in Norwegian, while at the same time using QRegularExpressionValidator to ensure the name is in fact a valid name (no non-letter characters).

So the question is, do I have to list all such accented characters exhaustively, or is there some kind of "word class" that can be used, that allows me to trust Qt to provide an updated list for me?

What would be the best approach?

Upvotes: 2

Views: 591

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626929

Yes, there is a \p{L} Unicode category class that will match all Unicode base letters.

This will match 1 or more letter chunks:

QRegularExpression re("\\p{L}+");

All uppercase letter variants: \p{Lu}

All lowercase letter variants: \p{Ll}

See Unicode categories for more information.

Upvotes: 3

Related Questions