「C++」regex_replaceで指定文字をすべて置き換えるサンプル
書式
regex_replace(対象の文字列, regex(正規表現),置換文字)
使用例
#include <iostream>
#include <regex>
using namespace std;
int main() {
string strA = regex_replace("this is a test", regex("t"), "pp");
cout << "置換結果" <<endl;
cout << strA << endl;
return 0;
}
#include <iostream>
#include <regex>
using namespace std;
int main() {
string strA = regex_replace("this is a test", regex("t"), "pp");
cout << "置換結果" <<endl;
cout << strA << endl;
return 0;
}
#include <iostream> #include <regex> using namespace std; int main() { string strA = regex_replace("this is a test", regex("t"), "pp"); cout << "置換結果" <<endl; cout << strA << endl; return 0; }
実行結果
置換結果
pphis is a ppespp