I am trying to extract axis name from a string using regex library from STL library, but encountered some issues. Below is my code:
#include <string>
#include <iostream>
#include <regex>
using namespace std;
int main(){
std::string line;
std::cmatch cm;
if(std::regex_match("axis=x y z", cm, std::regex("axis=(.*)"))){
for(auto x: cm) std::cout << x << std::endl;
}
}
The output is
axis=x y z
=x y z
My question is why the second matching group is not x y z but with an extra = sign?
Also, if I replace the regular expression with "axis=(\\w*)" to capture the first axis name, I will get an error:
terminate called after throwing an instance of 'std::regex_error'
what(): regex_error
Aborted
What's the cause for this issue?