So I have the following text in a std::string:
2: enp1s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000\ link/ether 68:f7:28:4e:7b:ac brd ff:ff:ff:ff:ff:ff
and I am trying to extract the 'enp1s0' and '68:f7:28:4e:7b:ac' using the following regex:
\d{1}:\s+(\w+).*link\/ether\s{1}([a-z0-9:]+)
which works in an online regex tester, but this C++ code does not detect a match:
std::regex interface_address("^\\d{1}:\\s+(\\w+).*link\\/ether\\s{1}([a-z0-9:]+)");
std::smatch pieces;
if (std::regex_match(line, pieces, interface_address)) {
std::string name = "";
std::string address = "";
for (size_t i = 0; i < pieces.size(); ++i) {
auto submatch = pieces[i];
if (i == 0) {
name = submatch.str();
} else if (i == 1) {
address = submatch.str();
}
}
std::cout << name << address << std::endl;
}
where am i going wrong?
{1}in a regexp. That's the default for any pattern.regexwellpieces[1]and address is inpieces[2].pieces[0]is the match for the entire regexp.