// ^: 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
function stringNotContainingSubstring($pattern, $text) {
return preg_match($pattern, $text) === 1;
}
$pattern = "/^((?!notype).)*$/i";
echo stringNotContainingSubstring($pattern, " notype") ? "true\n" : "false\n";
echo stringNotContainingSubstring($pattern, "notype ") ? "true\n" : "false\n";
echo stringNotContainingSubstring($pattern, "notypevar") ? "true\n" : "false\n";
echo stringNotContainingSubstring($pattern, "anotypevar") ? "true\n" : "false\n";
echo stringNotContainingSubstring($pattern, "anotype") ? "true\n" : "false\n";
echo stringNotContainingSubstring($pattern, "The only approval you need is your own") ? "true\n" : "false\n";
echo stringNotContainingSubstring($pattern, "Follow your dreams") ? "true\n" : "false\n";
echo stringNotContainingSubstring($pattern, "Never regret anything that made you smile") ? "true\n" : "false\n";
echo stringNotContainingSubstring($pattern, "A programming language") ? "true\n" : "false\n";
/*
run:
false
false
false
false
false
true
true
true
true
*/