Trying to understand basic regex functions in C++ -
i've done regular expressions in perl years , trying utilize them in c++. having problems though. want parse through string such translate(0.0,-572.36218)
, grab 2 numerical values.
here's have far:
std::cmatch m; std::regex e("([-|\.|0-9]*),([-|\.|0-9]*)" ); std::regex_search ("translate(0.0,-572.36218)",m,e); float xtransform = atof(m[1].first); float ytransform = atof(m[2].first);
however when @ values in debugger here's see:
m[0].first = "0.0,-572.36218)" m[1].first = "0.0,-572.36218)" m[3].first = "-572.36218)";
if use regex debugging tool (like regex coach) can see regular expression syntactically correct. guess don't know if i'm doing right, or how extract data need cmatch
instance.
update: must missing something, because if change regular expression this:
std::regex e("([0-9])");
m returns being 2 entries deep , each entry's first element = "0.0,-572.36218)". why matching parenthesis beyond me. , [0-9] seem have no effect.. matches every character. fristrating. :(
you should have used \\.
. when used \.
, matched whole string - because \.
escaped c .
. later .
multiplied *
in [-|.|0-9]*
match anything.
Comments
Post a Comment