Boost logo

Boost Users :

Subject: Re: [Boost-users] regex_replace
From: John Maddock (boost.regex_at_[hidden])
Date: 2012-02-06 11:44:39


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.


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