I have strings of 15 characters long. I am performing some pattern matching on it with a regular expression. I want to know the position of the substring where the IsM
Rather than use IsMatch(), use Matches:
const string stringToTest = "abcedfghijklghmnopqghrstuvwxyz";
const string patternToMatch = "gh*";
Regex regex = new Regex(patternToMatch, RegexOptions.Compiled);
MatchCollection matches = regex.Matches(stringToTest);
foreach (Match match in matches )
{
Console.WriteLine(match.Index);
}