我正在阅读一个包含以下内容的日志文件
DateTime: 2012-12-09 17:00:18
Command: ALTER INDEX [XPKAttribute] ON [FMC360Train_MSCRM].[MetadataSchema].[Attribute] REORGANIZE WITH (LOB_COMPACTION = ON)
Comment: ObjectType: Table, IndexType: Clustered, ImageText: No, NewLOB: No, FileStream: No, AllowPageLocks: Yes, PageCount: 1336, Fragmentation: 10.1796
Outcome: Succeeded
Duration: 00:00:01
DateTime: 2012-12-09 17:00:19
DateTime: 2012-12-09 17:00:19
Command: ALTER INDEX [XPKLocalizedLabel] ON [FMC360Train_MSCRM].[MetadataSchema].[LocalizedLabel] REORGANIZE WITH (LOB_COMPACTION = ON)
Comment: ObjectType: Table, IndexType: Clustered, ImageText: No, NewLOB: Yes, FileStream: No, AllowPageLocks: Yes, PageCount: 2522, Fragmentation: 18.5964
Outcome: Succeeded
Duration: 00:00:01
DateTime: 2012-12-09 17:00:20
这是我正在使用的正则表达式代码
var data = new Regex(@"^DateTime:\ (?<StartTime>[^\r]+)\r\nCommand: ALTER INDEX\ (?<Command>[^\r]+)\r\nComment:\ (?<Comment>[^\r]+)\r\nOutcome:\ (?<Outcome>[^\r]+)\r\nDuration:\ (?<Duration>[^\r]+)\r\nDateTime:\ (?<EndTime>[^\r]+)", RegexOptions.Multiline)
.Matches(File.ReadAllText(@"C:\Users\dalvi\Desktop\Index Logs\trial.txt")).Cast<Match>().Select(m => new
{
StartTime = m.Groups["StartTime"].Value,
Command = m.Groups["Command"].Value,
Comment = m.Groups["Comment"].Value,
Outcome = m.Groups["Outcome"].Value,
Duration = m.Groups["Duration"].Value,
EndTime = m.Groups["EndTime"].Value
});
但是输出我在命令之后得到整个文本:和评论:但是我想要在 ON 之后的文本意味着 [FMC360Train_MSCRM].[MetadataSchema].[LocalizedLabel] 然后下一个文本 REORGANIZE 作为不同的值,我该如何修改正则表达式代码得到像这样的输出
StartTime DBTableName Type Comment Outcome Duration EndTime
2012-12-09 17:00:18 [FMC360Train_MSCRM].[MetadataSchema].[Attribute] REORGANIZE PageCount: 1336 Succeeded 00:00:01 2012-12-09 17:00:19
我的程序正在努力获得长输出,但我想要以上述格式输出,所以我只需要正则表达式的帮助。