gpt4 book ai didi

混沌输入中的正则表达式路径匹配

转载 作者:行者123 更新时间:2023-12-01 11:15:59 25 4
gpt4 key购买 nike

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

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 行出现。我想知道是否可以使用一个正则表达式来完成我需要的事情。

最佳答案

使用这个:

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

我在 [^\r\n] 之后添加了一个否定前瞻 ((?!...)) 以防止它在您的情况下继续匹配再次遇到起始模式。从您已有的内容中,我发现它是最直接的。

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

关于混沌输入中的正则表达式路径匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17823057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com