
Hi I have a problem with the following std::string stmp = "PORT (127,0,0,1,6,56)\r"; cout << stmp << endl; 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); output is 127.0.0.1 if I change to this stmp = "PORT 127,0,0,1,6,56\r";// remove the '(' and' )' the output is 127,0,0,1 what do I have to change in the boost::regex regex_ip to get 127.0.0.1 dots instead of comma appreciate any help Christer

I am not an expert in Regex but try to substitute the commas between the parenthesis by \. (backslash dot), escaping the dot. regex_ip(".+\\(([0-9]{1,})\.([0-9]{1,})\.([0-9]{1,})\.([0-9]{1,})\.([0-9]{1,})\.([0-9]{1,})\\).*"); Note: I have not tested it. Hope this helps, Mau. On Mon, Feb 6, 2012 at 11:47 AM, Christer Borgqvist < christer.borgqvist10@bredband.net> wrote:
Hi
I have a problem with the following std::string stmp = "PORT (127,0,0,1,6,56)\r"; cout << stmp << endl; 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);
output is 127.0.0.1 if I change to this stmp = "PORT 127,0,0,1,6,56\r";// remove the '(' and' )' the output is 127,0,0,1 what do I have to change in the boost::regex regex_ip to get 127.0.0.1 dots instead of comma
appreciate any help Christer
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

No application crash, the only changes is in std::string stmp = "PORT (127,0,0,1,6,56)\r"; this works with 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", out 127.0.0.1 to std::string stmp = "PORT 127,0,0,1,6,56\r"; this not. out PORT (127,0,0,1,6,56) if i change to boost::regex regex_ip(".+\([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,})\.*"); the out is 7.0.0.1 I must change something in the regex_ip but i cant figure it out. Christer "Mauricio Gomes" <mgpensar@gmail.com> skrev i meddelandet news:CAP4BRxwmujxDz3VWDJTWuF0Wamy04zMeA1ODurvzRamqOPmTzg@mail.gmail.com... I am not an expert in Regex but try to substitute the commas between the parenthesis by \. (backslash dot), escaping the dot. regex_ip(".+\\(([0-9]{1,})\.([0-9]{1,})\.([0-9]{1,})\.([0-9]{1,})\.([0-9]{1,})\.([0-9]{1,})\\).*"); Note: I have not tested it. Hope this helps, Mau. On Mon, Feb 6, 2012 at 11:47 AM, Christer Borgqvist <christer.borgqvist10@bredband.net> wrote: Hi I have a problem with the following std::string stmp = "PORT (127,0,0,1,6,56)\r"; cout << stmp << endl; 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); output is 127.0.0.1 if I change to this stmp = "PORT 127,0,0,1,6,56\r";// remove the '(' and' )' the output is 127,0,0,1 what do I have to change in the boost::regex regex_ip to get 127.0.0.1 dots instead of comma appreciate any help Christer _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users ------------------------------------------------------------------------------ _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

No application crash, the only changes is in std::string stmp = "PORT (127,0,0,1,6,56)\r"; this works with 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", out 127.0.0.1 to std::string stmp = "PORT 127,0,0,1,6,56\r"; this not. out PORT (127,0,0,1,6,56) if i change to boost::regex regex_ip(".+\([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,})\.*"); the out is 7.0.0.1 I must change something in the regex_ip but i cant figure it out. ~~~~~~~~~~~~~~ You're regular expression has literal ( and ) in it - the \\( and \\) parts, so.... not surprisingly these will only match if the text has literal ( and )'s. So either remove those from the expression or make them optional by using \\(? and \\)?. HTH, John.

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 /Christer "John Maddock" <boost.regex@virgin.net> skrev i meddelandet news:2787367C597B46F4A64E9AB393CAEC01@acerlaptop...
No application crash, the only changes is in std::string stmp = "PORT (127,0,0,1,6,56)\r"; this works with 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", out 127.0.0.1 to std::string stmp = "PORT 127,0,0,1,6,56\r"; this not. out PORT (127,0,0,1,6,56) if i change to boost::regex regex_ip(".+\([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,}),([0-9]{1,})\.*"); the out is 7.0.0.1
I must change something in the regex_ip but i cant figure it out.
~~~~~~~~~~~~~~
You're regular expression has literal ( and ) in it - the \\( and \\) parts, so.... not surprisingly these will only match if the text has literal ( and )'s. So either remove those from the expression or make them optional by using \\(? and \\)?.
HTH, John.

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.
participants (3)
-
Christer Borgqvist
-
John Maddock
-
Mauricio Gomes