var input = "d1048_m325";
//^d\d+_ -> the first letter is d followed by 4 digits and then an underscore.
var match = Regex.Match(input, "^d\d{4}_");
if(match.Success == false)
{
return null;
}
//the value is 'd1048_'. take the next 4 characters starting at the 2nd character
var result = match.Value.SubString(1, 4);
return int.Parse(result);