#include
#include
using namespace std;
#if 0
int main(){
string str;
cin >> str;
cout << regex_match(str, regex("\\d{4}-\\d{1,2}"));
return 0;
}
int main(){
string str ;
cout << "请输入邮箱:" << endl;
while (cin >> str){
if(regex_match(str, regex("[a-zA-Z0-9]+@1(26|63)\\.com")))
{
break;
}
cout << "输入错误,请重新输入:" << endl;
}
cout << "输入成功" < return 0; } //单个匹配 int main(){ string str="hello2023-03-20log"; smatch macth; //搜索的结果 regex pattern("(\\d{4})-(\\d{1,2})-(\\d{1,2})"); //搜索规则 ()表示把内容拿出来 if(regex_search(str,macth, pattern)) { cout<< "年:" << macth[1] << endl; cout<< "月:" < cout<< "日:" << macth[3] << endl; } return 0; } // 多个匹配 int main(){ string str="2023-03-21,2023-03-20,2023-03-19"; smatch macth; //搜索的结果 regex pattern("(\\d{4})-(\\d{1,2})-(\\d{1,2})"); //搜索规则 ()表示把内容拿出来 string::const_iterator citer = str.begin(); while (regex_search(citer, str.cend(),macth, pattern)) //循环匹配 { citer =macth[0].second; for (size_t i= 1;i < macth.size(); ++i) { cout << macth[i] << " "; } cout << endl; } return 0; } #endif int main() { cout << regex_replace("2023-03-20",regex("-"),"/") < return 0; }
下一篇:古代好听女子的名字