In the sample code, I saw a loop foreach
going through a matches regex
. Inside the loop there was a check for match.Success
. But will not all of these matches be successful? Otherwise, they do not match, right?
Am I mistaken in thinking that (in this situation) verification is redundant?
var regex = new Regex(pattern);
var matches = regex.Matches(input);
var list = new List<string>();
foreach (Match m in matches) {
if (m.Success) {
list.Add(m.Value);
}
}
source
share