using System; using System.Text.RegularExpressions; public class Test { public static void Main() { string[] strings = {"fx_2019.csv", "fx_201902.csv"}; foreach (string s in strings) { string myYear = Regex.Replace(s, @".*_(20[0-9]{2})[0-9]*\.\w+$", "$1"); Console.WriteLine(myYear); } } }