Extract comma separated portion of string with a RegEx in C#

后端 未结 4 1364
失恋的感觉
失恋的感觉 2021-01-22 17:22

Sample data: !!Part|123456,ABCDEF,ABC132!!

The comma delimited list can be any number of any combination of alphas and numbers

I want a regex to match the entri

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-22 18:02

    I think the RegEx you are looking for is this:

    (?:^!!PART\|){0,1}(?.*?)(?:,|!!$)
    

    This can then be run like this

            string tag = "!!Part|123456,ABCDEF,ABC132!!";
    
            string partRegularExpression = @"(?:^!!PART\|){0,1}(?.*?)(?:,|!!$)";
            ArrayList results = new ArrayList();
    
            Regex extractNumber = new Regex(partRegularExpression, RegexOptions.IgnoreCase);
            MatchCollection matches = extractNumber.Matches(tag);
            foreach (Match match in matches)
            {
                results.Add(match.Groups["value"].Value);
            }            
    
            foreach (string s in results)
            {
                Console.WriteLine(s);
            }
    

提交回复
热议问题