我想弄清楚我可以在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