使用PowerShell获取模式后的字符串值

使用PowerShell获取模式后的字符串值,powershell,Powershell,我想在下面的html代码片段中获取$ctrl后面的字符串: <div ng-if="$ctrl.CvReportModel.IsReady"> ng-click="$ctrl.confirmation()"></cs-page-btn> <cs-field field="$ctrl.CvReportModel.Product" ng-model="$ctrl.Upl

我想在下面的html代码片段中获取
$ctrl
后面的字符串:

 <div ng-if="$ctrl.CvReportModel.IsReady">
                              ng-click="$ctrl.confirmation()"></cs-page-btn>
                 <cs-field field="$ctrl.CvReportModel.Product" ng-model="$ctrl.UploadedFile.Product"></cs-field>
                 <cs-field field="$ctrl.CvReportModel.Month" ng-model="$ctrl.UploadedFile.Month"></cs-field>

我正在尝试使用
获取内容
选择字符串
执行此操作,但仍然无法获取所需的输出。

使用
获取内容
cmdlet读取文件,并使用
正则表达式
获取所需的内容:

$content = Get-Content 'your_file_path' -raw
$matches = [regex]::Matches($content, '"\$ctrl\.([^"]+)')
$matches | ForEach-Object {
    $_.Groups[1].Value
}
Regex:

"\$ctrl\.[^"]+
CvReportModel.IsReady
confirmation()
CvReportModel.Product
UploadedFile.Product
CvReportModel.Month
UploadedFile.Month
CvReportModel.IsReady
confirmation()
CvReportModel.Product
CvReportModel.Month

输出:

"\$ctrl\.[^"]+
CvReportModel.IsReady
confirmation()
CvReportModel.Product
UploadedFile.Product
CvReportModel.Month
UploadedFile.Month
CvReportModel.IsReady
confirmation()
CvReportModel.Product
CvReportModel.Month

另一种方法是使用
Select-String
cmdlet和带正向后视功能的
regex

Select-String -Path $scripts.tmp -Pattern '(?<=\$ctrl\.)[^"]+' | 
    ForEach-Object { $_.Matches.Value }
注意:
这将只返回每行的第一个
$ctrl.*
匹配项。但是,由于这与您所需的输出匹配,因此可能对您有用。

如果我希望所有匹配都在一行上,该怎么办?