I want to be able to find this pattern inside a c++ string. The pattern is as follows:
FIXED_WORD ANY_WORD(...)
where FIXED_WORD
refers to a fixed keyword and ANY_WORD
can be any word as long as a bracket follows from it.
I have tried using RegEx such as keyword \b(.*)\b\((.\*)\)
, where I tried to use the word boundary \b(.*)\b
to extract out ANY_WORD
followed by a bracket:
std::string s = "abcdefg KEYWORD hello(123456)";
std::smatch match;
std::regex pattern("KEYWORD \b(.*)\b\((.*)\)");
if (std::regex_search(s, match, pattern))
{
std::cout << "Match\n";
for (auto m : match)
std::cout << m << '\n';
}
else {
std::cout << "No match\n";
}
I am always getting a no match for this.