Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiline Regex matches first occurance but can't match second
    primarykey
    data
    text
    <p>I have a string in the format below. (I added the markers to get the newlines to show up correctly)</p> <pre><code>-- START BELOW THIS LINE -- 2013-08-28 00:00:00 - Tom Smith (Work notes) Blah blah b;lah blah 2013-08-27 00:00:00 - Tom Smith (Work notes) ZXcZXCZXCZX ZXcZXCZX ZXCZXcZXc ZXCZXC -- END ABOVE THIS LINE -- </code></pre> <p>I am trying to get a regular expression that will allow me to extract the information from the two separate parts of the string.</p> <p>The following expression matches the first portion successfully:</p> <pre><code>^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) - (.*) \\(Work notes\\)\n([\\w\\W]*)(?=\n\n\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2} - .* \\(Work notes\\)\n) </code></pre> <p>I am trying to figure out a way that I can modify it to get the second part of the string. I have tried things like what is below, but it ends up extending the match all the way to the end of the string. It is like it is giving preference to the expression following the OR.</p> <pre><code>^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) - (.*) \\(Work notes\\)\n([\\w\\W]*)(?:(?=\n\n\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2} - .* \\(Work notes\\)\n)|\n\\Z) </code></pre> <p>Any help would be appreciated</p> <p><strong>-- EDIT --</strong></p> <p>Here is a copy of the test program I created to try and get this correct. I also added a 3rd message and my RegEx above breaks in that case.</p> <pre><code>using System; using System.Text.RegularExpressions; namespace RegExTest { class MainClass { public static void Main (string[] args) { string str = "2013-08-28 10:50:13 - Tom Smith (Work notes)\nWhat's up? \nHow you been?\n\n2013-08-19 10:21:03 - Tom Smith (Work notes)\nWork Notes\n\n2013-08-19 10:10:48 - Tom Smith (Work notes)\nGood day\n\n"; var regex = new Regex ("^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) - (.*) \\(Work notes\\)\n([\\w\\W]*)\n\n(?=\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2} - .* \\(Work notes\\)\n)",RegexOptions.Multiline); foreach (Match match in regex.Matches(str)) { if (match.Success) { for (var i = 0; i &lt; match.Groups.Count; i++) { Console.WriteLine('&gt;'+match.Groups [i].Value); } } } Console.ReadKey(); } } } </code></pre> <p><strong>-- EDIT --</strong></p> <p>Just to make it clear, the data I am trying to extract is the Date and Timestamp (as one item), the name, and the "body" from each "paragraph".</p>
    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.
 

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