|
Boost Users : |
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.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net