27
1
using System;
2
using System.Collections.Generic;
3
using System.Text.RegularExpressions;
4
5
List<string> inputs = new()
6
{
7
"Nick", // no match
8
"Nick1", // no match
9
"1Nick", // no match
10
"Nick42", // match
11
"42Nick", // match
12
"4Nick2", // match
13
"42", // match
14
"1337", // match
15
"6", // no match
16
};
17
18
string pattern = "[0-9]+[a-zA-Z]*[0-9]+";
19
Regex regex = new Regex(pattern);
20
21
foreach (var input in inputs)
22
{
23
bool isMatch = regex.IsMatch(input);
24
Console.WriteLine(
25
$"'{input}' {(isMatch ? "did" : "did not")} " +
26
"match the pattern.");
27
}
Cached Result
Compilation error (line 9, col 9): Invalid token 'double' in class, struct, or interface member declaration
Compilation error (line 9, col 28): Identifier expected
Compilation error (line 9, col 33): Identifier expected
Compilation error (line 16, col 8): Invalid token 'double' in class, struct, or interface member declaration
Compilation error (line 9, col 28): Identifier expected
Compilation error (line 9, col 33): Identifier expected
Compilation error (line 16, col 8): Invalid token 'double' in class, struct, or interface member declaration