|
Boost Users : |
From: Jeff (jeff_j_dunlap_at_[hidden])
Date: 2008-03-18 21:11:06
Dear Regex Users:
I'd like to know if it is possible to check multiple expressions and specify
multiple patters within a single regex_replace statement. For example, I want
to replace .html extensions with .php and replace .gif with the .srf extension
Match: http://localhost/index.gif
replace with: http://localhost/index.srf
Match: http://localhost/index.html
replace with: http://localhost/index.php
Can this be done within a single regex_replace statement? Although this does
not work, it demonstrates what I am trying to achieve:
// trying to match either condition
const boost::regex sExp("(?:^(.*/)index\.html$) | (?:^(.*/)index\.gif$)");
// trying to replace according to matched extension
const std::string sRewrite("$1index.php");
std::string rewrite(const std::string& s) {
return boost::regex_replace(s, sExp, sRewrite, boost::match_perl |
boost::format_perl | boost::format_no_copy | boost::format_all);
}
int main() {
string s[5] = { "http://localhost/abc.png",
"http://localhost/abc.jpb",
"http://localhost/index.gif",
"http://localhost/hambone.srf",
"http://localhost/index.html" };
for(int i = 0; i < 5; ++i)
{
if (rewrite(s[i])!="")
{
cout << rewrite(s[i]) << endl;
}
}
return 0;
}
I don't know if regex_replace can be used to do this or not.
Thank you,
Jeff
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