Reputation: 11737
I'm working on C++,
I need to search for a given regular expression in given string. Please provide me the pointer to do it. I tried to use boost::regex library.
Following is the regular expression:
regular expression to search : "get*"
And above expression i have to search in following different strings: e.g.
1. "com::sun::star:getMethodName"
2. "com:sun:star::SetStatus"
3. "com::sun::star::getMessage"
so i above case i should get true for first string false for second and again true for third one. Thanks in advance.
Upvotes: 0
Views: 174
Reputation: 55897
boost::regex re("get.+");
example.
#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
Upvotes: 2