boost.regex get column?
Sep 3, 2013 at 3:01am UTC
so im using regular expressions to find text patterns(i love the original thoughts i have) and need to get the column of where a match starts, so in the example (some what) pseudo code:
1 2
regex_match("hello world" , regex("world" ))
cout<< regex_match.get_column();
it would print (assuming it starts at zero) 5
Sep 3, 2013 at 4:28pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <vector>
#include <string>
#include <boost/regex.hpp>
int main()
{
boost::cmatch result;
bool isMatch = boost::regex_search ("hello world" , result, boost::regex("world" )) ;
if (isMatch)
for ( unsigned i=0; i<result.size(); ++i )
std::cout << "Match occurred at position: " << result.position(i) << '\n' ;
else
std::cout << "No match found.\n" ;
}
DTSCode wrote:it would print (assuming it starts at zero) 5 6
Sep 3, 2013 at 5:32pm UTC
thank you!
Topic archived. No new replies allowed.