Reputation: 1479
foreach (Match match in Regex.Matches(line, "X"))
{
indexes.Add(match.Index);
}
I have a quick question. Here is my part of code, and I'm getting indexes of X's, but I also want to get indexes even if X's is in lowercase. What should I write?
Upvotes: 3
Views: 2486
Reputation: 369074
Use i
mode modifier (make the regular expression case-insensitive):
foreach (Match match in Regex.Matches(line, "(?i)X"))
or use RegexOptions.IgnoreCase
option:
foreach (Match match in Regex.Matches(line, "X", RegexOptions.IgnoreCase))
or specify both X
and x
:
foreach (Match match in Regex.Matches(line, "[Xx]"))
Upvotes: 5
Reputation: 10538
Without using regex you could just do Regex.Matches(line.ToLower(), 'x')
.
Upvotes: 3