Reputation: 1362
boost::regex re("(abc)(.*?)");
boost::smatch m;
std::string str = "abcdlogin";
boost::regex_search(str, m, re);
I found m[1].first is "abcdlogin", m[1].second is "dlogin".
But I think is m[1].first should be "abc"?
Upvotes: 1
Views: 1091
Reputation: 52395
As noted in the documentation:
m[n].first: For all integers n < m.size(), the start of the sequence that matched sub-expression n. Alternatively, if sub-expression n did not participate in the match, then last.
m[n].second: For all integers n < m.size(), the end of the sequence that matched sub-expression n. Alternatively, if sub-expression n did not participate in the match, then last.
Note how they are iterators into the matching sub-expression.
In your example, if you want a string with "abc"
, you can construct a string like this: std::string s(m[1].first, m[1].second);
.
Upvotes: 1