In the following example we match strings containing 'mail' or 'letter' or 'correspondence' but only match whole words i.e. not 'email'
Code:
1 2 3
| QRegExp rx("\\b(mail|letter|correspondence)\\b");
rx.indexIn("I sent you an email"); // returns -1 (no match)
rx.indexIn("Please write the letter"); // returns 17 |
The second string matches "Please write the
letter". The word 'letter' is also captured (because of the parentheses). We can see what text we've captured like this:
Code:
QString captured = rx.cap(1); // captured == "letter"