Capturing a repeated group

后端 未结 9 1531
[愿得一人]
[愿得一人] 2021-01-14 09:17

I am attempting to parse a string like the following using a .NET regular expression:

H3Y5NC8E-TGA5B6SB-2NVAQ4E0

and return the following u

9条回答
  •  野的像风
    2021-01-14 09:24

    I have discovered the answer I was after. Here is my working code:

        static void Main(string[] args)
        {
            string pattern = @"^\s*((?[ABCDEFGHJKLMNPQRSTVXYZ0123456789]{8})-?){3}\s*$";
            string input = "H3Y5NC8E-TGA5B6SB-2NVAQ4E0";
            Regex re = new Regex(pattern);
            Match m = re.Match(input);
    
            if (m.Success)
                foreach (Capture c in m.Groups["group"].Captures)
                    Console.WriteLine(c.Value);
        }
    

提交回复
热议问题