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