Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;正则表达式替换第一个匹配_C++_Regex_String_C++11 - Fatal编程技术网

C++ C++;正则表达式替换第一个匹配

C++ C++;正则表达式替换第一个匹配,c++,regex,string,c++11,C++,Regex,String,C++11,我试图编写一个类似Java的Matcher::replaceFirst(字符串替换)的方法。我知道如何用std::regex_replace替换std::regex_replace中的所有匹配项,但如何只替换字符串中正则表达式的第一个匹配项?您可以使用std::regex_replace和一个附加的标志,std::regex_常量::format_first_only,以获得您想要的结果 查看更多信息。您仍然可以使用std::regex\u replace,方法是将format\u first\

我试图编写一个类似Java的
Matcher::replaceFirst(字符串替换)
的方法。我知道如何用
std::regex_replace
替换
std::regex_replace
中的所有匹配项,但如何只替换字符串中正则表达式的第一个匹配项?

您可以使用
std::regex_replace
和一个附加的标志,
std::regex_常量::format_first_only
,以获得您想要的结果


查看更多信息。

您仍然可以使用
std::regex\u replace
,方法是将
format\u first\u only
指定为
std::regex\u replace()
的标志参数


请看这里

到目前为止,您尝试了哪些代码?