QRegExp regex("Hello World"); regex.indexIn("Say Hello World"); QString match = regex.cap(); // returns "Hello World"
QRegExp regex("(\\d+)"); regex.indexIn("123 456 789"); QStringList matches; for(int i = 0; i < regex.captureCount(); i++){ matches.append(regex.cap(i+1)); } // matches contains "123", "456", "789"In this example, we create a QRegExp object with the regular expression "(\\d+)" which matches one or more digits. We use the indexIn() function to search for matches in the string "123 456 789". We then use a loop and the captureCount() function to retrieve each matched group and append it to a QStringList. The QRegExp class is part of the QtCore library in the Qt package.