code_junkie

How can I find the index in a string that matches a boost regex?

Nov 11th, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. void index(boost::regex& re,const std::string& input){
  2. boost::match_results<std::string::const_iterator> what;
  3. boost::match_flag_type flags = boost::match_default;
  4. std::string::const_iterator s = input.begin();
  5. std::string::const_iterator e = input.end();
  6. while (boost::regex_search(s,e,what,re,flags)){
  7. std::cout << what.position() << std::endl;
  8. std::string::difference_type l = what.length();
  9. std::string::difference_type p = what.position();
  10. s += p + l;
  11. }
  12. }
  13.  
  14. int find_match_offset(std::string const& string_to_search,
  15. boost::regex const& expression)
  16. {
  17. boost::smatch results;
  18. if(boost::regex_match(string_to_search,results,expression))
  19. {
  20. return results.position()
  21. }
  22. return -1;
  23. }
Add Comment
Please, Sign In to add comment