Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C错误无法将sytem.text.regularexpressions.match转换为字符串_C#_Regex - Fatal编程技术网

C# C错误无法将sytem.text.regularexpressions.match转换为字符串

C# C错误无法将sytem.text.regularexpressions.match转换为字符串,c#,regex,C#,Regex,下面的代码块从HTML页面捕获文本,但我在下面的行中得到编译错误: St = Regex.Match(St, @"(?i)(?<= |^)order(?= |$) (?i)(?<= |^)Term (?i)(?<= |^)oF [0-9]* (?i)(?<= |^)years (?<= |^)or (?<= |^)Longer"); 代码块: 我能得到一些帮助吗?Regex.Match返回一个匹配对象;您需要对返回的Match对象调用.Value以获得匹配

下面的代码块从HTML页面捕获文本,但我在下面的行中得到编译错误:

St = Regex.Match(St, @"(?i)(?<= |^)order(?= |$) (?i)(?<= |^)Term (?i)(?<= |^)oF [0-9]* (?i)(?<= |^)years (?<= |^)or (?<= |^)Longer"); 
代码块:

我能得到一些帮助吗?

Regex.Match返回一个匹配对象;您需要对返回的Match对象调用.Value以获得匹配的子字符串

e、 g:


St=Regex.MatchSt,@?i?Regex.Match返回一个匹配对象,而不是字符串…..感谢您的帮助。
 if (textordernode.InnerHtml.Contains("Order Term"))
                {
                    String St = textordernode.InnerHtml;

                    St = St.Replace(@"\r", "");
                    St = St.Replace(@"\n", "");
                    St = Regex.Replace(St, @"<[^>]+>|&nbsp;", " ").Trim();
                    St = Regex.Match(St, @"(?i)(?<= |^)order(?= |$) (?i)(?<= |^)Term (?i)(?<= |^)oF [0-9]* (?i)(?<= |^)years (?<= |^)or (?<= |^)Longer");

                    int pFrom = St.IndexOf("Order Term of ") + "Order Term of ".Length;
                    int pTo = St.LastIndexOf("or longer");
                    try
                    {
                        textorderterm = St.Substring(pFrom, pTo - pFrom) + "or longer";
                        break;
                    }
                    catch (Exception ex)
                    {
                        textorderterm = "";
                        Console.WriteLine(ex.Message);
                    }
                }