QString str = "sdf com df ru"; qDebug() = str.indexOf("(com|ru)"); 

Returns -1; Did by Max Schlee, what is wrong?

    1 answer 1

    Try changing the code a bit and it will work:

     QString str = "sdf com df ru"; qDebug() << str.indexOf(QRegExp("(com|ru)")); 

    Most likely, your code is trying to strictly search for the substring "(com | ru)" in the text and does not perceive it as a regular expression, because in fact you are passing the string to the indexOf method, not the regular expression.