如何在c++中搜索正则表达式
How to search for a regular expression in c++?
我正在开发C++,
我需要在给定的字符串中搜索给定的正则表达式。请为我提供指针。我尝试使用boost::regex库。
以下是正则表达式:要搜索的正则表达式:"get*"
在上面的表达式中,我必须在以下不同的字符串中搜索:例如
1. "com::sun::star:getMethodName"
2. "com:sun:star::SetStatus"
3. "com::sun::star::getMessage"
所以我在上面的情况下,第一个字符串应该为true,第二个字符串为false,第三个字符串为true。提前谢谢。
boost::regex re("get.+");
例如。
#include <iostream>
#include <string>
#include <boost/regex.hpp>
#include <vector>
#include <algorithm>
int main()
{
std::vector<std::string> vec =
{
"com::sun::star:getMethodName",
"com:sun:star::SetStatus",
"com::sun::star::getMessage"
};
boost::regex re("get.+");
std::for_each(vec.begin(), vec.end(), [&re](const std::string& s)
{
boost::smatch match;
if (boost::regex_search(s, match, re))
{
std::cout << "Matched" << std::endl;
std::cout << match << std::endl;
}
});
}
http://liveworkspace.org/code/7d47ad340c497f7107f0890b62ffa609
相关文章:
- C++向后正则表达式搜索
- 可选搜索和正则表达式
- C++ 中用于搜索字符串模式的正则表达式
- 如何加快正则表达式搜索C++中大量潜在的大文件?
- 正则表达式C++如何搜索有效的 Linux 设备节点
- 对 std::string 执行正则表达式搜索和替换
- Eclipse IDE,正则表达式搜索和替换
- 尝试使用正则表达式搜索:C++
- 检索 C++ 中的正则表达式搜索
- 如何在c++中搜索正则表达式
- 在C++中使用正则表达式搜索.txt文件
- 找不到c++正则表达式搜索模式
- 相同的正则表达式搜索结果在C++和Java中有所不同
- 正则表达式搜索和替换C++中的组?
- C++ 使用正则表达式搜索"正则表达式运算符"
- 我如何在另一个进程的内存中通过正则表达式搜索字符串
- 用C++正则表达式搜索字符串中的文件路径
- 搜索/替换boost正则表达式
- 使用正则表达式搜索向量
- c++正则表达式搜索多行注释(在/* */之间)