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 行ではなく 1 行として表示されています。

4

1 に答える 1

1

これを使用してください:

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

開始パターンが再び一致した場合に一致し続けるのを防ぐために、(?!...)直後に否定先読み ( ) を追加しました。[^\r\n]あなたがすでに得たものから、それが最も簡単だと思います。

結果を確認してください: http://regexr.com?35mjh

于 2013-07-24T00:12:44.240 に答える