Skip to content

Instantly share code, notes, and snippets.

@wanghuaisheng
Created January 22, 2018 09:34
Show Gist options
  • Save wanghuaisheng/a03dcd1eb5a28688d789a0c306e0ac20 to your computer and use it in GitHub Desktop.
Save wanghuaisheng/a03dcd1eb5a28688d789a0c306e0ac20 to your computer and use it in GitHub Desktop.
正则匹配组
         
         var pattern = @"^.+(?<No1>[\d]{5})$";
            var input = "abcd2018012200005";
            var rgx=new Regex(pattern);
            var mat=rgx.Match(input);
            if (mat.Success)
            {
                //Groups不会为null,通过组名取值也不会抛出异常
                var val=mat.Groups["No"].Value;
                var val2 = mat.Groups["No1"]?.Value;
            }
            
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment