Reputation: 900
I have strings like MA14
or MD22b
and I have to find the index between MA
and 14
.
Upvotes: 0
Views: 45
Reputation: 5395
Try with:
(?<=[A-Z])(?=\d)|(?<=\d)(?=[A-Z])
ind demo the ()
for group capturing is added, to display indices on which it match.
Upvotes: 2
Reputation: 3253
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();
will print
0
ABC
3
142
(Dump
is from LINQPAd, you can use Console.WriteLine
etc).
Upvotes: 0