Regex Ends With Example

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

List<string> inputs = new()
{
    "Coding", // match
    "I love programming!", // no match
    "Coding is fun!", // no match
	"I love programming", // match
};

string pattern = "ing$";
Regex regex = new Regex(pattern);

foreach (var input in inputs)
{
    Match match = regex.Match(input);
    Console.WriteLine(
        $"'{input}' {(match.Success ? "did" : "did not")} " +
        "match the string ending with the pattern.");
}
;