#include <iostream>
#include <regex>
#include <string>
// ^: Matches the beginning of the string
// (?!notype): asserts that the current position in the string is not followed by the
// substring "notype"
// .: Matches any single character (except newline characters)
// *: Matches the preceding group (((?!notype).)) zero or more times
// $: Matches the end of the string
bool stringNotContainingSubstring(const std::string& pattern, const std::string& text) {
std::regex re(pattern, std::regex::icase);
return std::regex_search(text, re);
}
int main() {
std::string pattern = "^((?!notype).)*$";
std::cout << std::boolalpha; // Print bools as true/false
std::cout << stringNotContainingSubstring(pattern, " notype") << std::endl;
std::cout << stringNotContainingSubstring(pattern, "notype ") << std::endl;
std::cout << stringNotContainingSubstring(pattern, "notypevar") << std::endl;
std::cout << stringNotContainingSubstring(pattern, "anotypevar") << std::endl;
std::cout << stringNotContainingSubstring(pattern, "anotype") << std::endl;
std::cout << stringNotContainingSubstring(pattern, "The only approval you need is your own") << std::endl;
std::cout << stringNotContainingSubstring(pattern, "follow your dreams") << std::endl;
std::cout << stringNotContainingSubstring(pattern, "Never regret anything that made you smile") << std::endl;
std::cout << stringNotContainingSubstring(pattern, "A programming language") << std::endl;
}
/*
run:
false
false
false
false
false
true
true
true
true
*/