2010-11-02 87 views
1

我需要一個正則表達式將從看起來字符串中提取到一個文件的完整路徑,如:正則表達式。幫助需要

c:\DevProjects\Web Projects\RD_deploy\obj\Release\Source\App_Code\BusinessLogic\WebMethodTypes\WebCompressionResult.cs(33): error CS0246: The type or namespace name 'CompressionResult' could not be found (are you missing a using directive or an assembly reference?) 

c:\DevProjects\AssaultRifle.cs(157): error CS0246: The type or namespace name 'Gunpowder' could not be found (are you missing a using directive or an assembly reference?) 

回答

2

嘗試:

^(.*)\([0-9]+\):.*$ 

這應該做到這一點。

+0

我不能做分裂......我需要一場比賽。 – Agzam 2010-11-02 15:05:37

+0

這是一場比賽。在Perl中你可以這樣做:$ file = $ 1如果/^(.*)\([0-9]+\):.*$/ – krico 2010-11-02 15:33:38

2

^([^\(]+)

這將讓該字符串的開始,到第一個(,成組1;在你的情況下,整個路徑達到(33)...

編輯: 如果你的文件名可能有括號,事情會變得更復雜一些。

^(.+)(\(\d+\)):將匹配一切高達括號內的編號後面跟着冒號,像 「(33):」 或 「(157):」,成組1

+1

文件和目錄名稱可以包含'()'... – bjoernz 2010-11-02 15:11:53

1

嘗試此。

([a-zA-Z]:(?:\\\\\w+(?:\s+\w+)*)+\.\w+)