一个正则表达式匹配结果可以分成多个部分,这就是组(Group).
把一次Match结果用(?name)的方式分成组,例子:
public static void Main()
{
string s = "2005-2-21";
Regex reg = new Regex(@"(?yd{4})-(?md{1,2})-(?dd{1,2})",RegexOptions.Compiled);
Match match = reg.Match(s);
int year = int.Parse(match.Groups["y"].Value);
int month = int.Parse(match.Groups["m"].Value);
int day = int .Parse(match.Groups["d"].Value);
DateTime time = ne...[ 查看全文 ]