• 如何从字符串中提取相关内容


    实例1 sql语句相关

    1. {
    2. /**
    3. * \s 表示一个\t、一个\n等
    4. * \s Matches a whitespace character (QChar::isSpace()).
    5. * \s* 多个
    6. * \s+ 至少一个
    7. * \s{2} 两个
    8. * \s{1,2} 一个到两个
    9. * \w 表示一个字母、一个数字、一个汉字等
    10. * \w Matches a word character (QChar::isLetterOrNumber(), QChar::isMark(), or '_').
    11. * \w* 多个
    12. * \w+ 至少一个
    13. * \w{2} 两个
    14. * \w{1,2} 一个到两个
    15. * () 表示提取的位置
    16. */
    17. QString Output = "select obid from cey_bt_table where ch_billno = 'Q001' ";
    18. QRegExp rx(R"(select\s*(\w*)\s*from\s*(\w*)\s*where\s*(\w*)\s*=\s*'(\w*)'\s*)");
    19. rx.indexIn(Output);
    20. QStringList qsl = rx.capturedTexts();
    21. for(int i=0; i
    22. {
    23. qDebug()<<"Da Data Thing: "<< i << " Da Value Thing: " << qsl.at(i);
    24. }
    25. return 1;
    26. }

    运行结果:

    Da Data Thing: 0 Da Value Thing: "select obid from cey_bt_table where ch_billno = 'Q001' "

    Da Data Thing: 1 Da Value Thing: "obid"

    Da Data Thing: 2 Da Value Thing: "cey_bt_table"

    Da Data Thing: 3 Da Value Thing: "ch_billno"

    Da Data Thing: 4 Da Value Thing: "Q001"

    实例2 mac地址相关

    1. {
    2. /**
    3. * \d 表示一个数字
    4. * \d Matches a digit (QChar::isDigit()).
    5. * \d+ 表示重复一次或者多次 1、12、23
    6. * \d* 表示重复零次或者多次 _、12、11
    7. * \d{2} 表示只能匹配两个字符
    8. */
    9. QString Output;
    10. Output="Duration: 00:01:25.65, start: 0.050000, bitrate: 5200 kb/s";
    11. QRegExp rx = QRegExp(R"(Duration:\s*(\d{2}:\d{2}:\d{2}.\d{2}),\s*start:\s*(\d+\.\d+),\s*bitrate:\s*(\d*)\s*kb/s)");
    12. rx.indexIn(Output);
    13. QStringList qsl = rx.capturedTexts();
    14. for(int i=0; i
    15. {
    16. qDebug()<<"Da Data Thing: "<< i << " Da Value Thing: " << qsl.at(i);
    17. }
    18. }

    运行结果:

    Da Data Thing: 0 Da Value Thing: "Duration: 00:01:25.65, start: 0.050000, bitrate: 5200 kb/s"

    Da Data Thing: 1 Da Value Thing: "00:01:25.65"

    Da Data Thing: 2 Da Value Thing: "0.050000"

    Da Data Thing: 3 Da Value Thing: "5200"

  • 相关阅读:
    关于企业中台规划和 IT 架构微服务转型
    QtWebEngine性能问题
    藏在超级应用背后的逻辑和哲学
    详解MAC帧、ARP、DNS、ICMP协议
    使用Spring Cloud设计电商系统架构
    高性能本地缓存Ristretto(一)——存储策略
    华为od项目
    C++ Qt 学习(一):Qt 入门
    当你离开现在的公司,你的百万业务量还能保持吗?
    【c++刷题Day2】专题3栈与队列&单调栈与单调队列T4
  • 原文地址:https://blog.csdn.net/ch593030323/article/details/128133499