c# How to check every single line with Regex.IsMatch
c#, multiline, regex
Solution
bool match = sStringToCheck
.Split(new string[] {Environment.NewLine}, StringSplitOptions.None)
.Any(line => new Regex(@"^\S+ [A-Z]{1,3}$").IsMatch(line));
will check every line. Is that your goal?
Problem
I'm using `new Regex("(?m)^\S+ [A-Z]{1,3}$").IsMatch(sStringToCheck)` to check a multiline string. My issue is, that it only appears to validate the last line of the string. This list passes: - ABC-12345-DEF A - ABC-12345-DEF A 123 - ABC-12345-DEF A This list fails: - ABC-12345-DEF A - ABC-12345-DEF A - ABC-12345-DEF A 123 However, I would like fail both, as each contains a not matching line. Thanks!