CSharp · Console
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
List<string> inputs = new()
{
"Nick", // no match
"Nick1", // no match
"1Nick", // no match
"Nick42", // match
"42Nick", // match
"4Nick2", // match
"42", // match
"1337", // match
"6", // no match
};
string pattern = "[0-9]+[a-zA-Z]*[0-9]+";
Regex regex = new Regex(pattern);
foreach (var input in inputs)
{
bool isMatch = regex.IsMatch(input);
Console.WriteLine(
$"'{input}' {(isMatch ? "did" : "did not")} " +
"match the pattern.");
}