首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

急正则取值取不到!该怎么解决

2012-05-23 
急?正则取值取不到!string RegexString title.+?/titlestring pageStr 2323232323titleSaly

急?正则取值取不到!
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"); 

热点排行