【发布时间】:2017-03-15 17:50:54
【问题描述】:
每当找到\w*\w 模式时,我都会尝试将* 替换为。这是我所拥有的
#include <string>
#include <iostream>
#include <regex>
using namespace std;
int main() {
string text = "Dear Customer, You have made a Debit Card purchase of INR962.00 on 26 Oct. Info.VPS*Brown House. Your Net Available Balance is INR 5,584.58.";
regex reg("[\w*\w]");
text = regex_replace(text, reg, " ");
cout << text << "\n";
}
但它也将* 替换为,并将w 替换为。
上述程序的输出是
Dear Customer, You have made a Debit Card purchase of INR962.00 on 26 Oct. Info.VPS Bro n House. Your Net Available Balance is INR 5,584.58.
【问题讨论】:
-
regex reg(R"((\w)\*(?=\w))");并替换为"$1 " -
regex
[ ]并不是你想的那样, -
[\w*\w]表示替换任何字符w或*。
标签: c++ regex string c++11 replace