Regex regexObj = new Regex(
@"([A-Za-z_][A-Za-z_0-9]*)(:)(([-+*%])?(\d*\.?\d*)?)*"
, RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
var subjectString = "a:123+456;b:456;";
Match matchResults = regexObj.Match(subjectString);
while (matchResults.Success) {
for (int i = 1; i < matchResults.Groups.Count; i++) {
Group grp = matchResults.Groups[i];
if (grp.Success) {
Console.WriteLine("st:" + grp.Index + ", len:" + grp.Length + ", val:" + grp.Value);
}
}
matchResults = matchResults.NextMatch();
}
出力:
st:0、len:2、val:.a
st:2、len:1、val ::
st:6、len:0、val:
st:6、len:0、val: