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 ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.