I am attempting to use Qt to execute a regex in my C++ application. I have done similar regular expressions with Qt in C++ before, but this one is proving difficult.
Given a string with optional _# at the end of the string, I want to extract the part of the string before that.
Examples:
"blue_dog" should result "blue_dog"
"blue_dog_1" should result "blue_dog"
"blue_dog_23" should result "blue_dog"
This is the code I have so far, but it does not work yet:
QString name = "blue_dog_23";
QRegExp rx("(.*?)(_\\d+)?");
rx.indexIn(name);
QString result = rx.cap(1);
I have even tried the following additional options in many variations without luck. My code above always results with "":
rx.setMinimal(TRUE);
rx.setPatternSyntax(QRegExp::RegExp2);