Game Programming using Qt 5 Beginner's Guide - Second Edition
by Pavel Strakhov, Witold Wysota, Lorenz Haas
What just happened?
In the first line, we constructed the aforementioned QRegularExpression object, while passing the regular expression's pattern as a parameter to the constructor. Note that we have to escape the \ character, because it has special meaning in C++ syntax.
Regular expressions are case-sensitive by default. However, we want to allow the input to be in uppercase or mixed case. To achieve this, we can, of course, write (mg|mG|Mg|MG|g|G|kg|kG|Kg|KG) or convert the string to lowercase before matching, but there is a much cleaner and more readable solution. On the second line of the code example, you see the answer—a pattern option. We used setPatternOptions() to set the QRegularExpression::CaseInsensitiveOption option, which does ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access