I'm currently attempting to check if a specific word is contained in a user-entered string. I'm using Regular Expressions and have the following code:
class Program
{
static void Main(string[] args)
{
string input = @"oaaawaala";
string word = "Owl";
string pattern = Regex.Replace(word, ".", ".*$0");
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase;
var found = Regex.Matches(input, pattern, options).Count > 0;
Console.WriteLine("Found: {0}", found);
}
}
The value of 'found' in the above code is true as the word 'Owl' is found in the input 'oaaawaala', based on the 'pattern'.
However, if I change the sequence of input to 'alaawaaao' or if the input is scrambled any other way, the value of 'found' is false since the pattern no longer matches. The Solution I need is that the 'word' should be found in any given string - scrambled or unscrambled. Any suggestions on how to go about this.
Thanks
o,wandlto be matched in this order or in any order?