给出一个字符串:
$assemblyVersion = '[assembly: AssemblyFileVersion("8.0.0.866")]'
我有一个可以找到程序集号的正则表达式:
(\d+\.)(\d+\.)(\d+\.)(\*|\d+)
这些行确认已找到匹配项:
$extractedVersion = $assemblyVersion -match "(\d+\.)(\d+\.)(\d+\.)(\*|\d+)";
然后如何从原始字符串$assemblyVersion
中提取匹配项?
阅读this article我不知道你是怎么做的......
我试过了:
$assemblyVersion
$extractedVersion = $assemblyVersion -match "?<assembly>(\d+\.)(\d+\.)(\d+\.)(\*|\d+)";
Write-Host "Extracted " $extractedVersion["assembly"]
不起作用。
我的正则表达式可能也不是最优的。
此stackoverflow answer无效
答案 0 :(得分:0)
我明白了:
$assemblyVersion = '[assembly: AssemblyFileVersion("8.0.0.866")]'
$assemblyVersion -match "(\d+\.)(\d+\.)(\d+\.)(\*|\d+)";
Write-Host "Extracted " $matches[0]