首页 相关文章 正则学习:组的定义及引用方式

正则学习:组的定义及引用方式

  一个正则表达式匹配结果可以分成多个部分,这就是组(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...[ 查看全文 ]

2016-02-19 标签:

正则学习:组的定义及引用方式的相关文章

手机页面
收藏网站 回到头部