日期:2014-05-18  浏览次数:21006 次

急?正则取值取不到!
string RegexString = "<title>.+?</title>";
  string pageStr = "2323232323<title>Salyani Technologies (P) Ltd.</title>23232323232";
  string resString = "";
  Regex reg = new Regex(RegexString, RegexOptions.IgnoreCase);
  MatchCollection matches = reg.Matches(pageStr);
  foreach (Match match in matches)
  {
  resString += match.Groups[1].Value;
  }
  Response.Write(resString+"/Test");



------解决方案--------------------
RegexString = "<title>.+?</title>";
=>
RegexString = "<title>(.+?)</title>";

------解决方案--------------------
string RegexString = ".*?<title>.+?</title>.*?";
------解决方案--------------------
C# code

  string RegexString = ".*?<title>(.+?)</title>.*?";
            string pageStr = "2323232323<title>Salyani Technologies (P) Ltd.</title>23232323232";
            string resString = "";
            Regex reg = new Regex(RegexString, RegexOptions.IgnoreCase);
            MatchCollection matches = reg.Matches(pageStr);
            foreach (Match match in matches)
            {
                resString += match.Groups[1].Value;
            }

------解决方案--------------------
一种这样
C# code

  string RegexString = "<title>(.+?)</title>";
  string pageStr = "2323232323<title>Salyani Technologies (P) Ltd.</title>23232323232";
  string resString = "";
  Regex reg = new Regex(RegexString, RegexOptions.IgnoreCase);
  MatchCollection matches = reg.Matches(pageStr);
  foreach (Match match in matches)
  {
  resString += match.Groups[1].Value;
  }
  Response.Write(resString+"/Test");