我想获取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>
所以我想尝试输出:
CvReportModel.IsReady
confirmation()
CvReportModel.Product
CvReportModel.Month
我正在尝试使用Get-Content
和Select-String
,但仍然无法获得所需的输出。
答案 0 :(得分:4)
使用Get-Content
cmdlet读取您的文件,并使用regex
获取所需内容:
$content = Get-Content 'your_file_path' -raw
$matches = [regex]::Matches($content, '"\$ctrl\.([^"]+)')
$matches | ForEach-Object {
$_.Groups[1].Value
}
<强>正则表达式:强>
"\$ctrl\.[^"]+
<强>输出:强>
CvReportModel.IsReady
confirmation()
CvReportModel.Product
UploadedFile.Product
CvReportModel.Month
UploadedFile.Month
另一种使用Select-String
cmdlet和regex
具有正面lookbehind的方法:
Select-String -Path $scripts.tmp -Pattern '(?<=\$ctrl\.)[^"]+' |
ForEach-Object { $_.Matches.Value }
<强>输出:强>
CvReportModel.IsReady
confirmation()
CvReportModel.Product
CvReportModel.Month
注意:强>
这只会返回每行的第一个 $ctrl.*
匹配。但是,由于这符合您所需的输出,因此对您来说非常有用。