$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2007-08-20 02:49:11
John Maddock <john <at> johnmaddock.co.uk> writes:
> 
> izua wrote:
> > How can I do a regex search that will return me all patterns for the
> > given regular expression?
> > Somehow like preg_match_all in PHP.
> 
> Please see my previous reply: 
> http://article.gmane.org/gmane.comp.lib.boost.user/29880
> 
> John. 
> 
Here is an example:
#include <iterator>
#include <boost/regex.hpp>
#include <boost/bind.hpp>
using namespace std;
using namespace boost;
vector<string> preg_match_all(const string & s, const regex & expr)
{
        typedef regex_iterator<string::const_iterator> iter;
        vector<string> res;
        transform
        (
                iter(s.begin(), s.end(), expr),
                iter(),
                back_inserter(res),
                bind(&iter::value_type::str, _1, 0)
        );
        return res;
}
preg_match_all("abcd123.ef56\tessn", regex("[0-9]+?[\\W]+?"));
Roman Perepelitsa.