开发者

linux c/c++ preg_replace type of function?

开发者 https://www.devze.com 2023-02-19 02:20 出处:网络
I\'m trying to figure out an preg_replace() (php) style function that 开发者_JS百科I can use in c++ (linux).

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

0

精彩评论

暂无评论...
验证码 换一张
取 消