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"之间的内容,并将内容匹配为*,但是运行后直接就退出了,也没有替换成功,请问各位这是什么原因?
- 点赞
- 写回答
- 关注问题
- 收藏
- 复制链接分享
- 邀请回答
为你推荐
- Mac Eclipse C++ "Binary not found" 求解决
- c++
- 2个回答
- 没有与指定类型匹配的 重载函数 "maxn" 实例
- c++
- 6个回答
- Visual Studio 的c++中的system("pause");暂停,在Xcode中类似作用的是什么?
- c++
- 2个回答
- python 正则匹配读取本地文件
- java
- c++
- 正则表达式
- python
- 2个回答
- 【C++】一个字符串分解问题
- 字符串
- c++
- 2个回答
- c++,字符串为什么只能减单引号?
- c++
- string
- 字符串find
- 1个回答
- c++如何识别指定字符串?
- c++
- 图片
- 10个回答
- C/C++字符串截取的问题
- c++
- string
- 21个回答
- QT 查找文件中字符串并替换的问题
- c++
- qt
- 1个回答
- c++中如何在字符串中加入变量?
- c++
- sql
- mysql
- 3个回答
- c++中 string 字符串删去空字符
- 字符串
- c++
- string
- 2个回答
- c++中正则表达式匹配问题
- c++
- 正则表达式
- 1个回答
- c++从文件中查找特定的字符串
- c++
- 6个回答
- 求正则表达式,匹配引号中内容
- 正则表达式
- 1个回答
- C++中字符串中交换字符的问题
- 字符串
- c++
- 8个回答
- 怎么用C++实现简单的正则表达式?
- c++
- 正则表达式
- 2个回答
- 为啥C++字符数组存字符串出错?
- c++
- 字符数组
- 指针
- 5个回答
- 带有通配符的字符串匹配算法
- 匹配
- 字符
- 通配符
- 3个回答
- C++中如何用正则表达式表示包含特定字符的网址
- c++
- 正则表达式
- 1个回答
- 手机号码校验 正则表达式匹配有问题 C++11可以通过 android下匹配失败 SOS!
- android
- c++
- 正则表达式
- 7个回答