For example I have an input: "Test your Internet connection bandwidth. Test your Internet connection bandwidth." (two times repeated) and I want to search for strings internet and bandwidth.
string keyword = tbSearch.Text //That holds value: "internet bandwidth"
string input = "Test your Internet connection bandwidth. Test your Internet connection bandwidth.";
Regex r = new Regex(keyword.Replace(' ', '|'), RegexOptions.IgnoreCase);
if (r.Matches(input).Count == siteKeyword.Split(' ').Length)
{
//Do something
}
This doesn’t work cause it finds 2 “internet” and 2 “bandwidth”, so it count 4 but the keyword length is 2. So what I can do?
First part is generating pattern from your keywords. If there is two keywords
"internet bandwidth", then generated regex pattern will look like:"(?=.*\binternet\b)(?=.*\bbandwidth\b)"It will match following inputs:
Following inputs will not match (not all words contained):
Another option (verifying each keyword separately):