[algorithm][string] regex_finder examples

Hi, I noticed that there are no examples for using regex_finder with find_iterator. I checked the test & example directories in libs, and also the documentation. I found nothing useful. Could someone provide a quick example? So far here is what I have, but it does not compile: *#include <iostream> #include <string> #include <boost/algorithm/string.hpp> #include <boost/algorithm/string_regex.hpp> #include <boost/regex.hpp> int main() { std::string queryKey = "/foo/bar//stuff/"; boost::find_iterator<std::string::iterator> keyIt( queryKey, boost::regex_finder( boost::regex( "/.*?" ) ) ); boost::find_iterator<std::string::iterator> end; for( ; keyIt != end; ++keyIt ) { std::cout << "\"" << *keyIt << "\"\t" << (*keyIt).size() << std::endl; } std::cout << std::endl; system( "pause" ); return 0; }*

AMDG Robert Dailey wrote:
I noticed that there are no examples for using regex_finder with find_iterator. I checked the test & example directories in libs, and also the documentation. I found nothing useful. Could someone provide a quick example? So far here is what I have, but it does not compile:
It compiles for me with the trunk, but crashes at runtime.
boost::find_iterator<std::string::iterator> keyIt( queryKey, boost::regex_finder( boost::regex( "/.*?" ) ) );
Don't pass a temporary regex to regex_finder. The find_iterator ends up holding a reference to a destroyed regex. In Christ, Steven Watanabe
participants (2)
-
Robert Dailey
-
Steven Watanabe