I have some html code like
<tr class="class1">
<td class="class2">
<a href="some_address"></a>
<div id="id1">
<span class="class3"></span>
</div>
<span>Just a text</span>
</td>
</tr>
I need to extract the piece of code between <tr class="class1">
and </tr>
tags. I use this regular expression https://regex101.com/r/Z0Pmgg/1
. And it seems it works. But, when I am trying to use this expression in C++ STL it doesn't work at all :(
#include <string>
#include <regex>
#include <iostream>
int main()
{
std::string str = "<tr class=\"class1\">\n"
"<td class=\"class2\">\n"
"<a href=\"some_address\"></a>\n"
"<div id=\"id1\">\n"
"<span class=\"class3\"></span>\n"
"</div>\n"
"<span>Just a text</span>\n"
"</td>\n"
"</tr>\n";
std::cmatch result;
std::regex regular("(<tr class=\"class1\">)"
"([\s\S]*?)"
"(<\/tr>)");
if (std::regex_match(str.c_str(), result, regular))
std::cout << "Success\n" << result[2] << std::endl;
return 0;
}
What am I doing wrong? I also tried to to use regex_search() instead