boost regex expression
Posted sssblog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了boost regex expression相关的知识,希望对你有一定的参考价值。
Boost.Regex provides three different functions to search for regular expressions
1. regex_match
#include <boost/regex.hpp> #include <string> #include <iostream> int main() std::string s = "Boost Libraries"; boost::regex expr("\\w+\\s\\w+"); std::cout << std::boolalpha << boost::regex_match(s, expr) << std::endl; return 0;
boost::regex_match() compares a string with a regular expression. It will return true only if the expression matches the complete string.
2. regex_search
#include <boost/regex.hpp> #include <string> #include <iostream> int main() std::string s = "Boost Libraries"; boost::regex expr("(\\w+)\\s(\\w+)"); boost::smatch what; if (boost::regex_search(s, what, expr)) std::cout << what[0] << std::endl; std::cout << what[1] << "_" << what[2] << std::endl; return 0;
3. regex_replace
#include <boost/regex.hpp> #include <string> #include <iostream> int main() std::string s = " Boost Libraries"; boost::regex expr("\\s"); std::string fmt("_"); std::cout << boost::regex_replace(s, expr, fmt) << std::endl; return 0;
以上是关于boost regex expression的主要内容,如果未能解决你的问题,请参考以下文章
致命错误 C1083:无法打开包含文件:'boost/regex.hpp':没有这样的文件或目录