在c#中有正則表達式,我可以用它來刪除一些任意字符或字符範圍,如Regex.Replace(str, "[^a-zA-Z0-9_.]+", "", RegexOptions.Compiled)
。但是在C++中相當於什麼。我知道Boost有一個正則表達式庫。但是對於這個操作,它是否可行以及它的性能如何?什麼是從C++中的字符串中刪除字符的最好和最快捷的方式?相當於Regex.Replace in C++
0
A
回答
0
你可能想boost::regex_replace:
#include <boost/regex.hpp>
#include <string>
const std::string input;
boost::regex matcher("[^a-zA-Z0-9_.]+");
const std::string formatter("");
std::string output = boost::regex_replace(input, matcher, formatter);
0
我使用了Boost,發現它既快速又易於使用。舉個例子:
#include <boost/regex.hpp>
bool detect_mypattern(const string& text)
{
// A specific regex pattern
static const boost::regex ep("[\\w\\s]{8}\\s{1}\\w{2}\\s{1}Test");
return(boost::regex_match(text, ep));
}
當然,如果你不需要正則表達式的力量,有大量的字符串函數,可能可以做的拼接字符更快的工作在一個字符串。
相關問題
- 1. 相當於SQL IN子句
- 2. MySQL「IS IN」相當於?
- 3. 相當於cmd的python「for %% a in(%*)做」
- 4. 相當於C#
- 5. C#相當於pydoc
- 6. C/C++相當於C#System.Net.Mail
- 7. 在CAML中相當於SQL IN
- 8. Cassandra API相當於「SELECT ... FROM ... WHERE id IN('...','...','...');」
- 9. LINQ to Dataset - 相當於sql(where ... in ...)
- 10. Django 1.1相當於'in'運算符
- 11. appengine相當於一個「NOT IN」查詢
- 12. 的Mnesia相當於SQL的NOT IN
- 13. C#相當於InStrRev
- 14. C#ULONG_PTR相當於
- 15. C#相當於FREAD
- 16. C-pstree相當於
- 17. httplib相當於C
- 18. C++相當於tailq
- 19. strtoul相當於C#
- 20. C++相當於java.lang.Integer.MIN_VALUE
- 21. ungetc相當於c#
- 22. C#相當於fprintf
- 23. 「if x in array」中的nvelocity/C#相當於什麼?
- 24. C#相當於OBJ-C的
- 25. c#regex.replace vs regex.matches
- 26. CLOCKS_PER_SEC相當於在C#
- 27. 的SAXParser相當於在C#
- 28. Java相當於C#代碼
- 29. C#Regex.Replace():獲取值
- 30. C#相當於ActionScript3的BitmapData
它的提升,你不能去那個錯了,我會說 – 2012-04-24 15:32:05
如果你真的關心性能,使用[Boost.Xpressive(HTTP:// www.boost.org/libs/xpressive/)(特別是它的靜態正則表達式),而不是Boost.Regex。 – ildjarn 2012-04-24 16:47:42