While I'm sure this could probably be handled with some crazy regex nested expression and capturing, I think it'd be pretty difficult. So, unless someone here is a regex god, I propose the following somewhat inefficient solution:
Code:
static bool IsMatch(string s) {
// Get length
if ((s == null) || (s.Length != 9)) {
return false;
}
// Must be between 7 and 9 1's
string t = s.Replace(@"1",String.Empty);
switch (9 - t.Length) {
case 7:
case 8:
case 9:
// Must have the remainder as *'s
return (t.Replace(@"*",String.Empty).Length == 0);
default:
return false;
}
}
I tested it with .NET 2.0 with your examples, and they all worked.
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum