Код: Выделить всё
string text1 = "Name 2000";
string text2 = "Name";
string text3 = "2000 2012";
string text4 = "2012 Name";
public static int get_title_year(string title)
{
string pattern = @"\b(?\d{4})";
Regex rx = new Regex(pattern);
if (rx.IsMatch(title))
{
Match match = rx.Match(title);
return Convert.ToInt16(match.Groups[1].Value);
}
else
{
return 0;
}
}
2000 0 2000 2012
Вместо
2000 0 2012 2012
Подробнее здесь: https://stackoverflow.com/questions/140 ... xpressions