Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try to use this pattern and Regex.Matches:</p> <pre><code>@"Record #(?&lt;RecordNumber&gt;\d*) with LeadRecordID (?&lt;LeadRecordId&gt;\d*) and MTN of [^\r\n]* has (?&lt;NumberOfErrors&gt;\d*) errors:(?:\r\n|)*(?&lt;Errors&gt;(?:\s{3}[^\r\n]+(?:\r\n)*)+)" </code></pre> <p>Test code:</p> <pre><code> static void Main(string[] args) { string pattern = @"Record #(?&lt;RecordNumber&gt;\d*) with LeadRecordID (?&lt;LeadRecordId&gt;\d*) and MTN of [^\r\n]* has (?&lt;NumberOfErrors&gt;\d*) errors:(?:\r\n|)*(?&lt;Errors&gt;(?:\s{3}[^\r\n]+(?:\r\n)*)+)"; string message = @"Record #1 with LeadRecordID 4 and MTN of (813) 555-1234 has 4 errors: Shipping Street Address cannot be blank Shipping City cannot be blank Shipping Zipcode cannot be blank Errors exist in secondary records #2, #3, #4, record not processed. Record #2 with LeadRecordID 5 and MTN of (813) 555-4321 has 1 errors: Shipping Street Address cannot be blank"; MatchCollection mc = Regex.Matches(message, pattern); foreach (Match m in mc) { Console.WriteLine("RecordNumber = \"{0}\"", m.Groups["RecordNumber"].Value); Console.WriteLine("LeadRecordId = \"{0}\"", m.Groups["LeadRecordId"].Value); Console.WriteLine("NumberOfErrors = \"{0}\"", m.Groups["NumberOfErrors"].Value); Console.WriteLine("Errors = \"{0}\"", m.Groups["Errors"].Value); MatchCollection errors = Regex.Matches(m.Groups["Errors"].Value, @"\s{3}(?&lt;error&gt;[^\r\n]+)(?:\r\n)*"); foreach(Match g1 in errors) { Console.WriteLine(g1.Groups["error"].Value); } Console.WriteLine("------------------------"); } Console.ReadLine(); } </code></pre> <p>Result:</p> <pre><code>RecordNumber = "1" LeadRecordId = "4" NumberOfErrors = "4" Errors = " Shipping Street Address cannot be blank Shipping City cannot be blank Shipping Zipcode cannot be blank Errors exist in secondary records #2, #3, #4, record not processed. " Shipping Street Address cannot be blank Shipping City cannot be blank Shipping Zipcode cannot be blank Errors exist in secondary records #2, #3, #4, record not processed. ------------------------ RecordNumber = "2" LeadRecordId = "5" NumberOfErrors = "1" Errors = " Shipping Street Address cannot be blank" Shipping Street Address cannot be blank ------------------------ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload