1. 提取字符串中指定的数据
下面这个示例是用来提取xml文件中dds_domain_id这个节点的值。
#include <iostream>
#include <regex>
int main()
{
std::string filecontent = "<xml><dds_domain_id>3</dds_domain_id></xml>";
std::regex reg("<dds_domain_id>(\\d)</dds_domain_id>");
std::smatch m;
bool ret = std::regex_search(filecontent.cbegin(), filecontent.cend(),m, reg);
if (ret)
{
// create face sdk config file
std::cout << m.str(1) << std::endl; // 这里的“1”对应于正则表达式中的第一个括号
}
else
{
std::cout << "not found" << std::endl;
}
return 0;
}
输出结果:3