·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> 正则表达式中的组集合的使用

正则表达式中的组集合的使用

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23

简单实例:

    string s = "2005-2-21";
    Regex reg = new Regex(@"(?<y>\d{4})-(?<m>\d{1,2})-(?<d>\d{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 = new DateTime(year,month,day);