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(); }
sTrmp0=str.split('(');
sTemp1=sTemp0[1].split(')');
结果:
sTemp1[0]="12-16";
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 tempStr = "123456(12-16)123123";//sr.ReadToEnd();
string pattern = @"[^(]+(\([^)]+\))[\s\S]*";
tempStr = Regex.Replace(tempStr, pattern, "$1");//输出:(12-16)
string str = "123456(12-16)123123"; int v1 = str.IndexOf("(");
int v2 = str.IndexOf("-");
int v3 = str.IndexOf(")"); string str1 = str.Substring(v1 + 1, v2 - v1 - 1);
string str2 = str.Substring(v2 + 1, v3 - v2 - 1);
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 [] split = str.Split(new Char[] {'(' , ')'});string [] split2 = split[1].Split(new Char[] {'- '});
split2 就是你要的结果12,16
string str = "123456(12-16)123123";
string str1=str.Remove(0, str.IndexOf("("));
MessageBox.Show(str1.Remove(str1.IndexOf(")")+1,(str1.Length-str1.IndexOf(")"))-1));
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去掉即可。
string[] array=Regex.Split(str1.Substring(1,str1.Length-2),@"\-");