Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to match a vector of regular expression with a one string?

If I want to verify one string is completely matches with the any one in the vector of strings then i will use

std::find(vectOfStrings.begin(), vectOfStrings.end(), "<targetString>") != v.end()

If the target string matches with any of the string in the vector then it will return true.

But what if i want to check one string is matches with any one of the vector of regular expressions? Is there any standard library i can use to make it work like std::find(vectOfRegExprsns.begin(), vectOfRegExprsns.end(), "<targetString>") != v.end()?

Any suggestions would be highly appreciated.

like image 390
Hari Krishna Nalla Avatar asked Oct 15 '25 18:10

Hari Krishna Nalla


1 Answers

How about using std::find_if() with a lambda?

std::find_if(
vectOfRegExprsns.begin(), vectOfRegExprsns.end(),
[](const std::string& item) { return regex_match(item, std::regex(targetString))});
like image 58
Sisir Avatar answered Oct 18 '25 07:10

Sisir