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

这样的正则表达式如何写

2012-01-31 
这样的正则表达式怎么写?字段1:字段一的内容字段2:字段二的内容字段3:字段三的内容...想把字段1和字段2之

这样的正则表达式怎么写?
字段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) ");

热点排行