I want to return output "match" if the pattern "regular" is a sub-string of variable st. Is this possible?
int main()
{
string st = "some regular expressions are Regxyzr";
boost::regex ex("[Rr]egular");
if (boost::regex_match(st, ex))
{
cout << "match" << endl;
}
else
{
cout << "not match" << endl;
}
}
The boost::regex_match only matches the whole string, you probably want boost::regex_search instead.
regex_search does what you want; regex_match is documented as
determines whether a given regular expression matches all of a given character sequence
(the emphasis is in the original URL I'm quoting from).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With