Qt利用正则表达式QRegExp提取括号内容

参考:
https://www.jb51.net/article/48765.htm?pc

https://blog.csdn.net/struggle6688/article/details/65444121?utm_medium=distribute.pc_relevant_t0.none-task-blog-OPENSEARCH-1.add_param_isCf&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-OPENSEARCH-1.add_param_isCf

    QString str = "sfsdfsdvsdthis is a sentence";

    QRegExp exp("(?:>)(.*)(?:<)"); //里面那两个 > < 可以替换成其他,但是要注意转义字符
    //QRegExp exp("(?:\\[)(.*)(?:\\])");

    qDebug() << "index:" << exp.indexIn(str);
    if(str.indexOf(exp) >= 0)
    {
        qDebug() << "something cap:" << exp.matchedLength();
        qDebug() << exp.cap(0);
    }

你可能感兴趣的:(Qt相关,正则表达式)