c# 截取字符串问题 (html文件很长就不贴了)

代码片段如下所示:

***
序列号:******
***其他代码***
*****未连接
序列号******
***其他代码***
*****未连接
序列号******
***其他代码***
*****已连接
序列号******
***其他代码***
*****未连接
***

(?is)序列号:.+?连接

分段,对每段执行

Substring(0,20)、Substring(match.Value.Length-3,3)

出现错误如图:
SN打下码不好意思
图片说明

  string pattern = @"(?is)序列号:.+?连接";
                    Regex rgx=new Regex(pattern);
                    Match match = rgx.Match(html);
                    if (match.Success)
                    {
                        result = match.Value.Substring(0,20)+" 状态:"+match.Value.Substring(match.Value.Length-3,3)+"\r\n";
                        foreach (Match m in rgx.Matches(html,match.Index+match.Length))
                        {
                            string y = m.Value;
                           // result += m.Value.Substring(0,20) + " 状态:" + m.Value.Substring(match.Value.Length - 3,3) + "\r\n";
                            string y1 = m.Value.Substring(match.Value.Length - 3, 3);
                            result += y.Substring(0, 20);
                            result += "状态:" + y.Substring(match.Value.Length - 3,3)+"\r\n";
                        }
string y = m.Value;
在这里打印输出下m.Value看看
Substring下标是不是超出了字符串长度的范围,比如<0或者>长度。
">看上去这里为空?