C# :从一段字符串中,输入开始和结束的字符,取中间的字符?

string s = "<FORM id=logInForm name=logInForm action=chk_rule.php method=post><INPUT type=hidden value=nf3a5776z23th8npzppq54z1j0d9z032 name=uid>

</FORM>";

Regex re = new Regex(@"\s+value=([^\s>]+)");

Match m = re.Match(s);
if (m.Success)
Console.WriteLine(m.Groups[1].Value);


++++++++++++++++++++++++++++++++++++++++++++++
起始,结束字符都是固定的,即不是带正则元字符的,其实用IndexOf也许更好些

string Start = "...";
string End = "...";


string s = "............";

int i = s.IndexOf(Start);
if (i >=0)
{
  int j= s.IndexOf(End, i+Start.Length);
  if (j >0)
  {
string Result = s.Substring(i+Start.Length, j-i-Start.Length);
  }
}


//********************* 正则判断是否存在某个字符串。

 //if (System.Text.RegularExpressions.Regex.IsMatch(html, "&uid="))
                            //{
                            //    return true;
                            //}

原文地址:https://www.cnblogs.com/Fooo/p/813875.html