我想在C ++中使用std::regex
从字符串中提取track 2数据。
我有一段代码,但它不起作用。这是代码:
std::string buff("this is ateststring;5581123456781323=160710212423468?hjks");
std::regex e (";\d{0,19}=\d{7}\w*\?", std::regex_constants::basic);
if(std::regex_match(buff, e))
{
cout << "Found!";
}
答案 0 :(得分:0)
整个目标序列必须与此函数的正则表达式匹配才能返回
true
(即,在匹配之前或之后没有任何其他字符)。对于仅在匹配只是序列的一部分时返回true
的函数,请参阅regex_search。
因此请尝试使用regex_search
:
std::regex e (";\\d{0,19}=\\d{7}\\w*\\?", std::regex_constants::basic);
if(std::regex_search(buff, e))
{
cout << "Found!";
}