Suppose input = “Hello” and pattern is “World”
I want to determinine that thr pattern does not occur in input.
Since pattern does not occur in input Regex.IsMatch should return true.
How can I write the pattern in C#
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Normally you don’t use regular expressions to check for whether a certain substring DOES NOT exist.
While it is possible in some (regex implementations) to use zero-width negative lookarounds (see this answer), it’s not necessarily possible for every input. Negative lookahead/behind assertions are primarily used when you want to avoid exponential matching failure in a regular expression by asserting that certain subcases do not exist before/after/within your match. They’re also (more commonly) used when searching for matches that must not be preceded or followed by some other pattern.
Instead, just check if the pattern exists in the input, and then return the negation of Regex.IsMatch: