mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2025-12-06 05:32:03 +01:00
24 lines
597 B
C#
24 lines
597 B
C#
using System.Text.RegularExpressions;
|
|
|
|
WriteLine("The default regular expression checks for at least one digit.");
|
|
|
|
do
|
|
{
|
|
Write("Enter a regular expression (or press ENTER to use the default): ");
|
|
string? regexp = ReadLine();
|
|
|
|
if (string.IsNullOrWhiteSpace(regexp))
|
|
{
|
|
regexp = @"^\d+$";
|
|
}
|
|
|
|
Write("Enter some input: ");
|
|
string input = ReadLine()!; // will never be null
|
|
|
|
Regex r = new(regexp);
|
|
|
|
WriteLine($"{input} matches {regexp}: {r.IsMatch(input)}");
|
|
|
|
WriteLine("Press ESC to end or any key to try again.");
|
|
}
|
|
while (ReadKey(intercept: true).Key != ConsoleKey.Escape); |