我有像MA14
或MD22b
这样的字符串,我必须找到MA
和14
之间的索引。
Try with:
(?<=[A-Z])(?='d)|(?<='d)(?=[A-Z])
演示()
用于组捕获,以显示与之匹配的索引。Simple regex:
string s = "ABC142";
var r= new Regex("^([A-Za-z]*)(''d*)$");
var m = r.Match(s);
m.Groups[1].Index.Dump(); # index of the match
m.Groups[1].ToString().Dump();
m.Groups[2].Index.Dump(); # index of the match
m.Groups[2].ToString().Dump();
将打印
0
ABC
3
142
(Dump
来自LINQPAd,你可以使用Console.WriteLine
等)