22
1
using System;
2
using System.Collections.Generic;
3
using System.Text.RegularExpressions;
4
5
List<string> inputs = new()
6
{
7
"Coding", // match
8
"I love programming!", // no match
9
"Coding is fun!", // no match
10
"I love programming", // match
11
};
12
13
string pattern = "ing$";
14
Regex regex = new Regex(pattern);
15
16
foreach (var input in inputs)
17
{
18
Match match = regex.Match(input);
19
Console.WriteLine(
20
$"'{input}' {(match.Success ? "did" : "did not")} " +
21
"match the string ending with the pattern.");
22
}
Cached Result
'Coding' did match the string ending with the pattern.
'I love programming!' did not match the string ending with the pattern.
'Coding is fun!' did not match the string ending with the pattern.
'I love programming' did match the string ending with the pattern.
'I love programming!' did not match the string ending with the pattern.
'Coding is fun!' did not match the string ending with the pattern.
'I love programming' did match the string ending with the pattern.