前进ing 2021-02-28 12:51 采纳率: 0%
浏览 76

C++正则匹配替换带""的字符串

#include <regex>    

#include <string>

#include <iostream>

#include<fstream>

using namespace std;

 

int main()

{

  

    string str="\"time\":2021-02-27,\"parament\":hello world,\"ip\":201.233.5.78,\"other\":ga21#";   

    regex repattern1("(?<=\"parament\":).*(?=,\"ip\")");

    smatch match1;

    string replace1="*";

    regex_match(str,match1,repattern1);

    cout<<boolalpha<<regex_match(str,repattern1)<<endl;

    cout<<match1[0]<<endl;

    cout<<regex_replace(str, repattern1, replace1)<<std::endl;

    system("pause");

    return 0;

}

这段代码匹配"time":2021-02-27,"parament":hello world,"ip":201.233.5.78,"other":ga21#中"parament":和,"ip"之间的内容,并将内容匹配为*,但是运行后直接就退出了,也没有替换成功,请问各位这是什么原因?

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-07 17:41
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器