【发布时间】:2025-12-23 17:40:09
【问题描述】:
我正在尝试从 .sln(Visual Studio 解决方案文件)中获取一串文本,以显示解决方案中包含哪些项目文件。
示例文本行是
Project("{xxxx-xxxxx-xxxx-xxxx-xx}") = "partofname.Genesis.Printing", "Production\partofname.Genesis.Printing\partofname.Genesis.Printing.csproj", "{xxx- xxx-xxx-xxx-xxxx}” 结束项目
我感兴趣的字符串部分是\和"之间的最后一部分。
\partofname.Genesis.Printing.csproj"
我使用的正则表达式是:
$r = [regex] "^[\\]{1}([A-Za-z.]*)[\""]{1}$"
我正在读取文件内容:
$sln = gci .\Product\solutionName.sln
我不知道在我的字符串选择语句中放什么。
我是 PowerShell 的新手,希望能提供任何帮助...
我之前确实有一个非常非常长期的方法,但我已经失去了工作......本质上它是为文件中的每一行做这个:
Select-String $sln -pattern 'proj"' | ? {$_.split()}
但是正则表达式会容易得多(我希望如此)。
【问题讨论】:
标签: regex string powershell substring