I am using regular expressions for performing site search.
If I search for this : “Villas at Millwood” (this is a community name) and the corresponding community name is “Villas at Millwood” , I get the results.
If I search for “Millwood villas” , there are no results populated.
I mean, the phrase is taken as a whole, and matched. Is there any way to match the any occurance of individual words in the entered phrase? so that “millwood Villas” would still bring the result of
“Villas at Millwood” ?
Here is what I have to match the community name :
Regex.IsMatch(MarketingCommunityName.Trim(), pattern, RegexOptions.IgnoreCase)
where pattern is the entered search phrase and the MarketingCommunityName is the actual community name.
Thanks in Advance!
Although I think that you should
Splityour search pattern at a space, and then check every word separately, it would not be too hard to construct an order-independent regular expression from your search pattern:This constructs a regex that contains one lookahead assertion per search word. Each lookahead assertion starts from the beginning of the string and looks whether the search word shows up anywhere inside the string. Note that you will likely get problems, if your
searchStringcontains regex meta-characters, so these should probably be escaped beforehand.