#include#include using namespace std; int main() { string str = "Hello World! 123"; if (regex_match(str, regex(".*123"))) cout << "String matches pattern." << endl; else cout << "String does not match pattern." << endl; return 0; }
#includeIn the above example, the matchString function is used to search for the pattern "brown" within the given string "The quick brown fox jumps over the lazy dog." The function checks whether the pattern exists within the string or not, and returns true or false accordingly. The package library used in this example is also the regex library.#include using namespace std; int main() { string str = "The quick brown fox jumps over the lazy dog."; if (regex_search(str, regex("brown"))) cout << "Pattern match found." << endl; else cout << "Pattern match not found." << endl; return 0; }