I'm trying to figure out an preg_replace() (php) style function that 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.