C ++ std :: regex track 2

时间:2013-12-10 16:54:01

标签: c++ regex

我想在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!";
                    }

1 个答案:

答案 0 :(得分:0)

来自regex_match documentation

  

整个目标序列必须与此函数的正则表达式匹配才能返回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!";
                }