3

我有一些混乱的日志输出,如下所示(是的,那些奇怪的新行实际上存在于那些地方。:)

C:\testing\testpath\testfile.txt
\\1.2.3.4\c$\test\testpath1\testpath2\k
\\1.2.3.4\c$\test\testpath1\testpath2\
C:\ro\row\rou\line.txt:line 234
Failed to grant AssetID=33683041 to UserID=44129434: Recipient already owns Asset at Corp.UserAsset.AwardUserAsset(Int6
4 assetReferenceId, Int32 userId, Boolean preventDuplicates, Boolean& awardedNewAsset) 
in d:\workspace\Trunk\Assemblies\SCL\CCL\BLL\UserAsset.cs:line 723 at Corp.UserAsset.AwardUserAsset(Int64 assetReferenceId, Int32 userId, Boolean preventDuplicates) in d:\workspace\Trunk\Assemblies\SCL\CCL\BLL\UserAsset.cs:line 710 at Corp.Website.Badge.Award.ProcessRequest(HttpContext context) in d:\workspace\Trunk\Web\CorpWebSite\Badge\Award.ashx.cs:line 111 at  System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

我想从正则表达式中得到的是这样的:

C:\testing\testpath\testfile.txt
\\1.2.3.4\c$\test\testpath1\testpath2\k
\\1.2.3.4\c$\test\testpath1\testpath2\
C:\ro\row\rou\line.txt:line 234
d:\workspace\Trunk\Assemblies\SCL\CCL\BLL\UserAsset.cs:line 723 at Corp.UserAsset.AwardUserAsset(Int64 assetReferenceId, Int32 userId, Boolean preventDuplicates) in
d:\workspace\Trunk\Assemblies\SCL\CCL\BLL\UserAsset.cs:line 710 at Corp.Website.Badge.Award.ProcessRequest(HttpContext context) in
d:\workspace\Trunk\Web\CorpWebSite\Badge\Award.ashx.cs:line 111 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

我目前有以下正则表达式

([\w]:\\|\\\\)([^\r\n]*)

但结果并不完全在那里我得到前 4 行但最后一个错误行只是作为单行而不是 3 出现。我想知道即使我需要的东西可以用一个正则表达式来完成。

4

1 回答 1

1

使用这个:

([\w]:\\|\\\\)(([^\r\n](?!([\w]:\\|\\\\)))*)

我在之后添加了一个否定的前瞻 ( (?!...))[^\r\n]以防止它在再次遇到您的起始模式时保持匹配。从你已经得到的东西中,我发现它是最直接的。

检查结果:http ://regexr.com?35mjh

于 2013-07-24T00:12:44.240 回答