我有一些混乱的日志输出,看起来像下面(是的那些奇怪的新行实际存在于那些地方。:)
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。 我想知道即使我需要的东西可以用一个正则表达式完成。
答案 0 :(得分:1)
使用这个:
([\w]:\\|\\\\)(([^\r\n](?!([\w]:\\|\\\\)))*)
我在(?!...)
之后添加了一个否定前瞻([^\r\n]
),以防止它再次遇到您的起始模式时保持匹配。我发现它比你已经得到的最直接。