linux c/c++ preg_replace type of function?
I'm trying to figure out an preg_replace() (php) style function that 开发者_JS百科I can use in c++ (linux).
Can someone help me translate this?
$str = preg_replace(array('/\s+/','/[^A-Za-z0-9\-]/'),array('-',''),$str);
Best option would be to link with the Perl Compatible Regular Expression (PCRE) library and use the functions it provides.
You can check pcrecpp(3)
for more info. A sample code would be:
#include <pcrecpp.h>
pcrecpp::RE("\s+").Replace("-", &s); // where s is the target string
pcrecpp::RE("[^A-Za-z0-9\-]").Replace("", &s);
You can use the boost::regex library
http://www.boost.org/doc/libs/1_46_1/libs/regex/doc/html/index.html
精彩评论