用正则取两则之间的数字?(c#和javascript两种方式)
d0s0s3t1p0to99999i3m0to99999c50m1rp1.htm
如有一个函数 string[] test(string start, string end)
调用时:test("s","s") 返回0,3
test("p","to") 返回0,99999
test("m","to") 返回0,99999
d0s0s3t1p0to99999i3m0to99999c50m1rp1.htm
如有一个函数 string[] test(string start, string end)
调用时:test("s","s") 返回0,3
test("p","to") 返回0,99999
test("m","to") 返回0,99999
{
int iStart = "d0s0s3t1p0to99999i3m0to99999c50m1rp1".IndexOf(start);
int iEnd = "d0s0s3t1p0to99999i3m0to99999c50m1rp1".IndexOf(end);if(iStart>=iEnd)
return;string strCut = "d0s0s3t1p0to99999i3m0to99999c50m1rp1".SubString(iStart,iEnd);MatchCollection matches = Regex.Matches(strCut , @"\d+");
foreach (Match match in matches)
{
string strLocation = match.ToString();//strLocation就是你想要的数据
}
}
但是要同时用START和END定位.不可能用一条正则搞定...
先问个问题,字符串“d0s0s3t1p0to99999i3m0to99999c50m1rp1”中, "to"不止一个,
是不是string end一定是在string start后面?
还有,这里的 "to"后面跟的都是 "99999", test("p","to") 返回0,99999是返回的p0to99999这两个数字还是p0to99999i3m0to99999两端的数字?