using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(\w*_abcd)\s*(?: (abcd_\w*);?)+";
string input = @" thing: random1_abcd
abcd_n1p3; abcd_n2p1
""random2_abcd"" does not exist.
thing: random3_abcd
abcd_n1p1; abcd_n2p3
thing: random4_abcd
abcd_n1p3; abcd_n3p1; abcd_n2p7
thing: random5_abcd
abcd_n4p2; abcd_n3p3; abcd_n6p7; abcd_n1p6
";
foreach (Match m in Regex.Matches(input, pattern))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx