[2] Fri 04Jun10 13:57:00 - (000035) USER t
[2] Fri 04Jun10 13:57:00 - (000035) PASS xxxxx
[2] Fri 04Jun10 13:57:00 - (000035) SYST
[2] Fri 04Jun10 13:57:00 - (000035) FEAT
[2] Fri 04Jun10 13:57:00 - (000035) CLNT FlashFXP 3.4.1.1149
[2] Fri 04Jun10 13:57:07 - (000035) RETR vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sending file d:\code\kenel\vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sent file d:\code\kenel\vssver.scc successfully (6.77 kB/sec - 208 Bytes)
[2] Fri 04Jun10 13:57:10 - (000035) RETR whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sending file d:\code\kenel\whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sent file d:\code\kenel\whatsnew.xml successfully (38.4 kB/sec - 944 Bytes)
[2] Fri 04Jun10 13:57:16 - (000035) RETR AppConfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sending file d:\code\kenel\appconfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully (4.81 kB/sec - 128 Bytes)
[2] Fri 04Jun10 13:57:00 - (000035) USER t1
[2] Fri 04Jun10 13:57:00 - (000035) PASS xxxxx
[2] Fri 04Jun10 13:57:00 - (000035) SYST
[2] Fri 04Jun10 13:57:00 - (000035) FEAT
[2] Fri 04Jun10 13:57:00 - (000035) CLNT FlashFXP 3.4.1.1149
[2] Fri 04Jun10 13:57:07 - (000035) RETR vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sending file d:\code\kenel\vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sent file d:\code\kenel\vssver.scc successfully (6.77 kB/sec - 208 Bytes)
[2] Fri 04Jun10 13:57:10 - (000035) RETR whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sending file d:\code\kenel\whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sent file d:\code\kenel\whatsnew.xml successfully (38.4 kB/sec - 944 Bytes)
[2] Fri 04Jun10 13:57:16 - (000035) RETR AppConfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sending file d:\code\kenel\appconfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully (4.81 kB/sec - 128 Bytes)
[2] Fri 04Jun10 13:57:00 - (000035) PASS xxxxx
[2] Fri 04Jun10 13:57:00 - (000035) SYST
[2] Fri 04Jun10 13:57:00 - (000035) FEAT
[2] Fri 04Jun10 13:57:00 - (000035) CLNT FlashFXP 3.4.1.1149
[2] Fri 04Jun10 13:57:07 - (000035) RETR vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sending file d:\code\kenel\vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sent file d:\code\kenel\vssver.scc successfully (6.77 kB/sec - 208 Bytes)
[2] Fri 04Jun10 13:57:10 - (000035) RETR whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sending file d:\code\kenel\whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sent file d:\code\kenel\whatsnew.xml successfully (38.4 kB/sec - 944 Bytes)
[2] Fri 04Jun10 13:57:16 - (000035) RETR AppConfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sending file d:\code\kenel\appconfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully (4.81 kB/sec - 128 Bytes)
[2] Fri 04Jun10 13:57:00 - (000035) USER t1
[2] Fri 04Jun10 13:57:00 - (000035) PASS xxxxx
[2] Fri 04Jun10 13:57:00 - (000035) SYST
[2] Fri 04Jun10 13:57:00 - (000035) FEAT
[2] Fri 04Jun10 13:57:00 - (000035) CLNT FlashFXP 3.4.1.1149
[2] Fri 04Jun10 13:57:07 - (000035) RETR vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sending file d:\code\kenel\vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sent file d:\code\kenel\vssver.scc successfully (6.77 kB/sec - 208 Bytes)
[2] Fri 04Jun10 13:57:10 - (000035) RETR whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sending file d:\code\kenel\whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sent file d:\code\kenel\whatsnew.xml successfully (38.4 kB/sec - 944 Bytes)
[2] Fri 04Jun10 13:57:16 - (000035) RETR AppConfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sending file d:\code\kenel\appconfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully (4.81 kB/sec - 128 Bytes)
不会写后面的截止条件
还是要你标出的红色部分的文本?有很多sent 文件的,有什么规律? Regex.Match("Sent file d:\code\kenel\whatsnew.xml successfully",@"(?i)[a-z]:(\\[^\\/: ?'""*<>]+)+").Value;能获得文件路径。但是你要其他的话,你要总结一下规律。
private static void TestRegex19()
{
string yourStr = @"[2] Fri 04Jun10 13:57:00 - (000035) USER t
[2] Fri 04Jun10 13:57:00 - (000035) PASS xxxxx
[2] Fri 04Jun10 13:57:00 - (000035) SYST
[2] Fri 04Jun10 13:57:00 - (000035) FEAT
[2] Fri 04Jun10 13:57:00 - (000035) CLNT FlashFXP 3.4.1.1149
[2] Fri 04Jun10 13:57:07 - (000035) RETR vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sending file d:\code\kenel\vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sent file d:\code\kenel\vssver.scc successfully (6.77 kB/sec - 208 Bytes)
[2] Fri 04Jun10 13:57:10 - (000035) RETR whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sending file d:\code\kenel\whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sent file d:\code\kenel\whatsnew.xml successfully (38.4 kB/sec - 944 Bytes)
[2] Fri 04Jun10 13:57:16 - (000035) RETR AppConfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sending file d:\code\kenel\appconfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully (4.81 kB/sec - 128 Bytes)
[2] Fri 04Jun10 13:57:00 - (000035) USER t1
[2] Fri 04Jun10 13:57:00 - (000035) PASS xxxxx
[2] Fri 04Jun10 13:57:00 - (000035) SYST
[2] Fri 04Jun10 13:57:00 - (000035) FEAT
[2] Fri 04Jun10 13:57:00 - (000035) CLNT FlashFXP 3.4.1.1149
[2] Fri 04Jun10 13:57:07 - (000035) RETR vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sending file d:\code\kenel\vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sent file d:\code\kenel\vssver.scc successfully (6.77 kB/sec - 208 Bytes)
[2] Fri 04Jun10 13:57:10 - (000035) RETR whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sending file d:\code\kenel\whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sent file d:\code\kenel\whatsnew.xml successfully (38.4 kB/sec - 944 Bytes)
[2] Fri 04Jun10 13:57:16 - (000035) RETR AppConfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sending file d:\code\kenel\appconfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully (4.81 kB/sec - 128 Bytes)
";
MatchCollection mc = Regex.Matches(yourStr, @"(?is)(?<=USER t\b.+?)[a-z]:(\\[^\\/: ?'""*<>\r\n]+)+(?=.+?USER|$)");
foreach (Match m in mc)
{
Console.WriteLine(m.Value);
}
}
结果:d:\code\kenel\vssver.scc
d:\code\kenel\vssver.scc
d:\code\kenel\whatsnew.xml
d:\code\kenel\whatsnew.xml
d:\code\kenel\appconfig.properties
d:\code\kenel\appconfig.properties
然后在这之间提取send file ... successfully之间的全路径.
private static void TestRegex19()
{
string yourStr = @"[2] Fri 04Jun10 13:57:00 - (000035) USER t
[2] Fri 04Jun10 13:57:00 - (000035) PASS xxxxx
[2] Fri 04Jun10 13:57:00 - (000035) SYST
[2] Fri 04Jun10 13:57:00 - (000035) FEAT
[2] Fri 04Jun10 13:57:00 - (000035) CLNT FlashFXP 3.4.1.1149
[2] Fri 04Jun10 13:57:07 - (000035) RETR vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sending file d:\code\kenel\vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sent file d:\code\kenel\vssver.scc successfully (6.77 kB/sec - 208 Bytes)
[2] Fri 04Jun10 13:57:10 - (000035) RETR whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sending file d:\code\kenel\whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sent file d:\code\kenel\whatsnew.xml successfully (38.4 kB/sec - 944 Bytes)
[2] Fri 04Jun10 13:57:16 - (000035) RETR AppConfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sending file d:\code\kenel\appconfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully (4.81 kB/sec - 128 Bytes)
[2] Fri 04Jun10 13:57:00 - (000035) USER t1
[2] Fri 04Jun10 13:57:00 - (000035) PASS xxxxx
[2] Fri 04Jun10 13:57:00 - (000035) SYST
[2] Fri 04Jun10 13:57:00 - (000035) FEAT
[2] Fri 04Jun10 13:57:00 - (000035) CLNT FlashFXP 3.4.1.1149
[2] Fri 04Jun10 13:57:07 - (000035) RETR vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sending file d:\code\kenel\vssver.scc
[3] Fri 04Jun10 13:57:07 - (000035) Sent file d:\code\kenel\vssver.scc successfully (6.77 kB/sec - 208 Bytes)
[2] Fri 04Jun10 13:57:10 - (000035) RETR whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sending file d:\code\kenel\whatsnew.xml
[3] Fri 04Jun10 13:57:10 - (000035) Sent file d:\code\kenel\whatsnew.xml successfully (38.4 kB/sec - 944 Bytes)
[2] Fri 04Jun10 13:57:16 - (000035) RETR AppConfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sending file d:\code\kenel\appconfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully (4.81 kB/sec - 128 Bytes)
";
MatchCollection mc = Regex.Matches(yourStr, @"(?is)(?<=USER t\b.+?)[a-z]:(\\[^\\/: ?'""*<>\r\n]+)+(?= successfully)(?=.+?USER|$)");
foreach (Match m in mc)
{
Console.WriteLine(m.Value);
}
}
运行结果:
d:\code\kenel\vssver.scc
d:\code\kenel\whatsnew.xml
d:\code\kenel\appconfig.properties
eg:
USER t
[3] Fri 04Jun10 13:57:10 - (000035) Sent file d:\code\kenel\whatsnew.xml successfully (38.4 kB/sec - 944 Bytes)
[2] Fri 04Jun10 13:57:16 - (000035) RETR AppConfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sending file d:\code\kenel\appconfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully (4.81 kB/sec - 128 Bytes)
asdasasaaookj
USER t1
[2] Fri 04Jun10 13:57:16 - (000035) RETR AppConfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sending file d:\code\kenel\appconfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
USER t
[2] Fri 04Jun10 13:57:16 - (000035) RETR AppConfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sending file d:\code\kenel\appconfig.properties
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
/regex/igs
USER t
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
USER t3
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
USER t2
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
USER t
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully红色为需要捕获的内容
{
string yourStr = @"USER t
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
USER t3
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
USER t2
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
USER t
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully";
MatchCollection mc = Regex.Matches(yourStr, @"(?is)(?<=USER t\b.+?)[a-z]:(\\[^\\/: ?'""*<>\r\n]+)+(?= successfully)(?=.+?(?:USER|$))");
foreach (Match m in mc)
{
Console.WriteLine(m.Value);
}
}
{
string yourStr = @"USER t
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
USER t3
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
USER t2
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
USER t
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully
[3] Fri 04Jun10 13:57:16 - (000035) Sent file d:\code\kenel\appconfig.properties successfully";
MatchCollection mc = Regex.Matches(yourStr, @"(?is)(?<=USER t\b.+?)[a-z]:(\\[^\\/: ?'""*<>\r\n]+)+(?= successfully)(?=.+?(?:USER|$))");
foreach (Match m in mc)
{
Console.WriteLine(m.Value);
}
}