简体   繁体   中英

linux c/c++ preg_replace type of function?

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);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM