まあ、私は正規表現の第一人者ではありませんが、これはうまくいくはずです:
string test = "####<Jun 22, 2012 12:54:18 PM CDT> <Notice> <WebLogicServer> <lname> <dname> <main>"
+ "<<WLS Kernel>> <> <BEA-000360> <Application started in RUNNING mode>";
var pattern = @"\<+(.*?)\>+";
var matches = Regex.Matches(test, pattern);
foreach (Match m in matches)
{
Console.WriteLine(string.Format("-{0}-", m.Groups[1]));
}
Console.ReadKey();
-
出力(文字間の実際の一致):
-Jun 22, 2012 12:54:18 PM CDT-
-Notice-
-WebLogicServer-
-lname-
-dname-
-main-
-WLS Kernel-
--
-BEA-000360-
-Application started in RUNNING mode-
string test = "####<Jun 22, 2012 12:54:18 PM CDT> <Notice> <WebLogicServer> <lname> <dname> <main> <<WLS Kernel>> <> <BEA-000360> <Application started in RUNNING mode>"
+ Environment.NewLine + "####<Jun 23, 2012 12:54:18 PM CDT> <Notice> <WebLogicServer> <lname> <dname> <main> <<WLS Kernel>> <> <BEA-000360> <Application started in RUNNING mode>"
+ Environment.NewLine + "####<Jun 24, 2012 12:54:18 PM CDT> <Notice> <WebLogicServer> <lname> <dname> <main> <<WLS Kernel>> <> <BEA-000360> <Application started in RUNNING mode>";
List<Foo> foo = new List<Foo>();
using (StringReader reader = new StringReader(test))
{
string line;
while ((line = reader.ReadLine()) != null)
{
string pattern = @"\<+(.*?)\>+";
var matches = Regex.Matches(line, pattern);
foo.Add(new Foo
{
Timestamp = matches[0].Groups[1].ToString(),
Field2 = matches[1].Groups[1].ToString()
});
}
}
出力:
それぞれ異なるタイムスタンプを持つ3つのFooオブジェクトのリスト(6月22日、6月23日、6月24日)