1
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"?

Mark Ma
  • 1,342
  • 3
  • 19
  • 35

1 Answers1

1

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);.

Jesse Good
  • 50,901
  • 14
  • 124
  • 166