1.string s="@张三 @李四 ";
获取“张三”和“李四”
MatchCollection mc = Regex.Matches(s, @"@(?<truename>\S+)[ | ]");
for (int i = 0; i < mc.Count; i++) //在输入字符串中找到所有匹配
{
var trueName=mc[i].Groups["truename"].Value);
}
2.string s="张三:say something<br/>李四:say something<br/>
替换成"<a name=‘AtTrueName‘>张三</a>:say something<br/><a name=‘AtTrueName‘>李四</a>:say something<br/>
即:在姓名的前后插入内容
Regex.Replace(s, "(?<begin>^|>)(?<truename>[^:]*):", "${begin}<a name=‘AtTrueName‘>${truename}</a>:")
原文:http://www.cnblogs.com/catzhou/p/4908233.html