|
Boost Users : |
Subject: Re: [Boost-users] regex_replace
From: John Maddock (boost.regex_at_[hidden])
Date: 2012-02-06 13:08:04
> Thanks for Your reply
> im closer but ther's a diffrent
> if i do as You say like this
> std::string stmp = "PORT (127,0,0,1,6,56)\r";
> boost::regex
> regex_ip(".+\\(?([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,})\\)?.*");
> std::string sip = boost::regex_replace(stmp, regex_ip, "$1.$2.$3.$4",
> boost::format_all);
> the output is
> 7.0.0.1
> but if i have the
> std::string stmp = "PORT (127,0,0,1,6,56)\r";
> boost::regex
> regex_ip(".+\\(([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,})\\).*");
> std::string sip = boost::regex_replace(stmp, regex_ip, "$1.$2.$3.$4",
> boost::format_all);
> the output is
> 127.0.0.1
>
> there is something i miss
Yep, the leading ".+" is greedy and is gobbling up more than you want it to.
Suggest you either make it non-greedy, or more precise.
John.
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