62,046
社区成员
发帖
与我相关
我的任务
分享
string s = "1、a人2bc2、b国de3、de1g12、d4中eb";
Response.Write(Regex.Replace(s, @"(?!^)(\d+、)", "<br/>$1"));
Response.Write("<br/>");
string s2 = "1、ABC2、BDE3、DEG12、DEB";
Response.Write(Regex.Replace(s2, @"(?!^)(\d+、)", "<br/>$1"));
/*
结果
1、a人2bc
2、b国de
3、de1g
12、d4中eb
1、ABC
2、BDE
3、DEG
12、DEB
*/
string s = "1、a人2bc2、b国de3、de1g12、d4中eb";
string result = Regex.Replace(s, @"(?!^)(\d+、)", "<br/>$1");
Response.Write(result);
string s = "1、A人2BC2、B国DE3、DE1G12、D4中EB";
MatchCollection mc = Regex.Matches(s, "\\d+、.*?(?=\\d+、)");
foreach (Match m in mc)
{
Response.Write(m.Value+"<br/>");
}
//能获取前三条数据
可以考虑将s智能扩展为1、A人2BC2、B国DE3、DE1G12、D4中EB100、 这样就正确
string s = "1、ABC2、BDE3、DEG12、DEB";
string result = Regex.Replace(s, @"(?<=\D)(?=\d+、)", "<br/>");
Console.WriteLine(result);
string s = "1、ABC2、BDE3、DEG12、DEB";
MatchCollection mc = Regex.Matches(s, "\\d+、[A-Z]+");//this update
foreach (Match m in mc)
{
Response.Write(m.Value+"<br/>");
}
string s = "1、ABC2、BDE3、DEG12、DEB";
MatchCollection mc = Regex.Matches(s, "\\d、[A-Z]+");
foreach (Match m in mc)
{
Response.Write(m.Value+"<br/>");
}
/*
1、ABC
2、BDE
3、DEG
2、DEB
*/