110,567
社区成员
发帖
与我相关
我的任务
分享
string str="123456(12-16)123123";
string [] split = str.Split(new Char[] {'(' , ')'});
string [] split2 = split[1].Split(new Char[] {'- '});
string str = "123456(12-16)123123";
Regex regex = new Regex(@"\(([^\-]+)\-([^\)]+)\)");
Match m = regex.Match(str);
while (m.Success)
{
Response.Write("<br/>");
Response.Write(m.Groups[1].Value);
Response.Write("<br/>");
Response.Write(m.Groups[2].Value);
m = m.NextMatch();
}
string tempStr = "123456(12-16)123123";//sr.ReadToEnd();
string pattern = @"[^(]+(\([^)]+\))[\s\S]*";
tempStr = Regex.Replace(tempStr, pattern, "$1");//输出:(12-16)
string input;
System.Text.RegularExpressions.MatchCollection mc = System.Text.RegularExpressions.Regex.Matches(input, "\(\d*-\d*\)");
foreach (System.Text.RegularExpressions.Match m in mc)
{
string[] splitArray = m.Value.Split('-');
//数组随便你怎么操作啦
}
string str1=Regex.Match(str,@"\(\d+\-\d+\)").Value;
string[] array=Regex.Split(str1.Substring(1,str1.Length-2),@"\-");
string inputs = "123456(12-16)123123";
Match mat = Regex.Match(inputs, @"((?<data1>[\d\w]*)\-(?<data2>[\d\w]*))", RegexOptions.Singleline);
Console.WriteLine(string.Concat("1:", mat.Groups["data1"].Value, " 2:", mat.Groups["data2"].Value));//1:12 2:16
根据这里括号内可以是数字或者字符,单是数字,把\W去掉即可。