In addition to
OriginalGriff[
^] answer, here is an implementation of His words ;)
string s = @"2015-04-22 JV RM - Save your list here 2014-12-28 SV See Word - Image in the mail2014-12-21 SV See word document02014-12-15 SV See word2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here. See the pdf in attach-2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here. See the pdf in attach-2014-12-15 SV See word2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here";
System.Text.RegularExpressions.Regex searchTerm =
new System.Text.RegularExpressions.Regex(@"(\d{4}-\d{2}-\d{2})");
var matches = from System.Text.RegularExpressions.Match match in searchTerm.Matches(s)
select new{match.Value, match.Index};
var matchedValues = matches.Select((Record,RowNo)=>new
{
Index = RowNo++,
Date = Record.Value,
GetTextFrom = Record.Index,
GetTextLength = matches.Skip(RowNo++).Take(1).Select(a=>a.Index - Record.Index).FirstOrDefault()
});
List<string> lines = new List<string>();
foreach(var line in matchedValues)
{
lines.Add(s.Substring(line.GetTextFrom, line.GetTextLength==0 ? s.Length - line.GetTextFrom : line.GetTextLength));
}
Dim s As String = "2015-04-22 JV RM - Save your list here 2014-12-28 SV See Word - Image in the mail2014-12-21 SV See word document02014-12-15 SV See word2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here. See the pdf in attach-2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here. See the pdf in attach-2014-12-15 SV See word2014-11-09 SV First small items to start programming here. See the pdf in attach2014-11-09 SV First small items to start programming here"
Dim searchTerm As New System.Text.RegularExpressions.Regex("(\d{4}-\d{2}-\d{2})")
Dim matches = From match In searchTerm.Matches(s) Select New With { _
match.Value, _
match.Index _
}
Dim matchedValues = matches.[Select](Function(Record, RowNo) New With { _
Key .Index = System.Math.Max(System.Threading.Interlocked.Increment(RowNo),RowNo - 1), _
Key .[Date] = Record.Value, _
Key .GetTextFrom = Record.Index, _
Key .GetTextLength = matches.Skip(System.Math.Max(System.Threading.Interlocked.Increment(RowNo),RowNo - 1)).Take(1).[Select](Function(a) a.Index - Record.Index).FirstOrDefault() _
})
Dim lines As New List(Of String)()
For Each line In matchedValues
lines.Add(s.Substring(line.GetTextFrom, If(line.GetTextLength = 0, s.Length - line.GetTextFrom, line.GetTextLength)))
Next
Result #1 (
matches
)
Value Index
2015-04-22 0
2014-12-28 39
2014-12-21 81
2014-12-15 113
2014-11-09 135
2014-11-09 215
2014-11-09 296
2014-11-09 376
2014-12-15 457
2014-11-09 479
2014-11-09 559
Result #2 (
matchedValues
)
Index Date GetTextFrom GetTextLength
0 2015-04-22 0 39
1 2014-12-28 39 42
2 2014-12-21 81 32
3 2014-12-15 113 22
4 2014-11-09 135 80
5 2014-11-09 215 81
6 2014-11-09 296 80
7 2014-11-09 376 81
8 2014-12-15 457 22
9 2014-11-09 479 80
10 2014-11-09 559 0
Result #3 (
lines
)
2015-04-22 JV RM - Save your list here
2014-12-28 SV See Word - Image in the mail
2014-12-21 SV See word document0
2014-12-15 SV See word
2014-11-09 SV First small items to start programming here. See the pdf in attach
2014-11-09 SV First small items to start programming here. See the pdf in attach-
2014-11-09 SV First small items to start programming here. See the pdf in attach
2014-11-09 SV First small items to start programming here. See the pdf in attach-
2014-12-15 SV See word
2014-11-09 SV First small items to start programming here. See the pdf in attach
2014-11-09 SV First small items to start programming here
[EDIT]
Ooopppsss... :omg:
I missed that question is taged as VB.NET. I'll improve my answer later ;)
Done (VB.NET code has been added)!