What is the qt regular expression to capture the text inside a parentheses?



  • hi all,
    I needed to capture the text inside a parentheses.
    For eg:
    hello how are u mr(abc+d) joy

    here i want to capture the text "abc+d"
    how can i do that?
    i tried but i didnt get how to use parentheses....
    please some one guide me



  • You will have to escape the parentheses using \.
    @
    QString text("hello how are u mr(abc+d) joy");

    QRegExp exp("\\((.*)\\)");
    if(exp.indexIn(text) >= 0)
    {
        qDebug() <&lt; exp.cap(0);   // "(acb+d)"
        qDebug() &lt;&lt; exp.cap(1);   // "abc+d"
    }
    

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.