#include <iostream>
#include <regex>
#include <string>
void set_args(string & text, const string& key, const string& value, bool add_args=true) {
regex re("([?&]+"+key + ")=[^&]+");
if (regex_search(text, re)){
text = regex_replace(text, re, "$1=" + value);
return;
}
if (add_args) {
if (text.find("?") == string::npos) {
text += "?" + key + "=" + value;
}else {
text += "&" + key + "=" + value;
}
}
}
int main()
{
string text = "?nBuf=3800&axBuf=48.00&wRate=1.0&Rate=1.0&Buf=48.00";
set_args(text, "axBuf", "123123");
cout<<"\n"<<text<<endl;
}
c++ regex 替换
最新推荐文章于 2024-01-07 03:43:56 发布