我想弄清楚我可以在C++(linux)中使用的preg_replace()(php)样式函数。linux c/C++ preg_replace类型的函数?
有人可以帮我翻译这个吗?
$str = preg_replace(array('/\s+/','/[^A-Za-z0-9\-]/'),array('-',''),$str);
我想弄清楚我可以在C++(linux)中使用的preg_replace()(php)样式函数。linux c/C++ preg_replace类型的函数?
有人可以帮我翻译这个吗?
$str = preg_replace(array('/\s+/','/[^A-Za-z0-9\-]/'),array('-',''),$str);
可以使用的boost :: regex库
http://www.boost.org/doc/libs/1_46_1/libs/regex/doc/html/index.html
Boost很不错,但preg_replace是PCRE的PHP绑定的一部分... – zarkdav 2011-03-23 20:00:05
最好的办法是与Perl Compatible Regular Expression(PCRE)库链接,并使用它提供的功能。
您可以检查pcrecpp(3)
获取更多信息。示例代码将是:
#include <pcrecpp.h>
pcrecpp::RE("\s+").Replace("-", &s); // where s is the target string
pcrecpp::RE("[^A-Za-z0-9\-]").Replace("", &s);
我删除的C代码,因为你是在写C++。 – Puppy 2011-03-23 19:54:23