I need a regular expression that will extract complete p开发者_运维百科ath to a file from a string that looks like:
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?)
or
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?)
Try:
^(.*)\([0-9]+\):.*$
This should do it.
^([^\(]+)
This will get the beginning of the string, up to the first (
, into group 1; in your case, the whole path up to (33)...
.
edit: If you might have parentheses in your filenames, things get a bit more complicated.
^(.+)(\(\d+\)):
will match everything up to a parenthesized number followed by a colon, like "(33):" or "(157):", into group 1.
Try this.
([a-zA-Z]:(?:\\\\\w+(?:\s+\w+)*)+\.\w+)
精彩评论