日期:2014-05-19  浏览次数:20848 次

这样的正则表达式怎么写?
字段1:字段一的内容   字段2:字段二的内容  
字段3:字段三的内容   ...

想把字段1和字段2之间的内容摘出来.

------解决方案--------------------
string sourceString = "字段1:字段一的内容 字段2:字段二的内容 字段3:字段三的内容 ";
System.Text.RegularExpressions.MatchCollection results = Regex.Matches(sourceString,@ "字段\d\:([^\s]*) ",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
foreach(Match result in results)
{
WL(result.Groups[1].Value);
}

//////////////////////////////////////////////
MSN:bdbox@hotmail.com请给我一个与您交流的机会!
------解决方案--------------------
string str = "字段1:字段一的內容 字段2:字段二的內容 字段3:字段三的內容 ";

Regex rg = new Regex(@ "(? <=:)\w+(?= ) ");

MatchCollection mc = rg.Matches(str);

foreach (Match m in mc)
{
Console.WriteLine(m.Value);
}
------解决方案--------------------
Regex rg = new Regex(@ "(? <=:)\w+ ");

------解决方案--------------------
Regex rg = new Regex(@ "(? <=字段1:)\s\S(?=字段2) ");