简体   繁体   中英

Regex pattern to extract a String

I've tried to extract the following string C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Microsoft.Common.targets from the below text.

This is my solution so far : \\s+((\\w:\\\\.*(?:\\()))

But this includes the "(" in the extracted string. How do I get rid of the "(" .

C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Microsoft.Common.targets (2015,5): error MSB3091: Task failed because "AxImp.exe" was not found, or the correct Microsoft Windows SDK is not installed. The task is looking for "AxImp.exe" in the "bin" subdirectory beneath the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0A\\WinSDK-NetFx40Tools-x86. You may be able to solve the problem by doing one of the following: 1) Install the Microsoft Windows SDK. 2) Install Visual Studio 2010. 3) Manually set the above registry key to the correct location. 4) Pass the correct location into the "ToolPath" parameter of the task.

Change the non-capturing group at the last to positive lookahead.

\s*((\w:\\.*(?=\()))

OR

\s+((\w:\\.*(?=\()))

And i also suggest you to change the inbetween .* to .*? , \\s*((\\w:\\\\.*?(?=\\())) in-order to provide a non-greedy match.

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM