Powershell 排除正则表达式(regex)从XML获取的参数
我在XML文件中有一个带掩码的参数:Powershell 排除正则表达式(regex)从XML获取的参数,powershell,Powershell,我在XML文件中有一个带掩码的参数: <id>ALL2-20210301-XXXXXX-XXXXX_X</id> 您不需要正则表达式,只需在“-”上拆分第二个元素,例如: $result=($date-split'-')[1] 它可能也比正则表达式快(还没有测量)。您不需要正则表达式,您可以在“-”上拆分,并使用第二个元素,例如: $result=($date-split'-')[1] 它可能也比正则表达式快(还没有测量)。有几种替代方法 $date = 'ALL2-2
<id>ALL2-20210301-XXXXXX-XXXXX_X</id>
您不需要正则表达式,只需在“-”上拆分第二个元素,例如:
$result=($date-split'-')[1]
它可能也比正则表达式快(还没有测量)。您不需要正则表达式,您可以在“-”上拆分,并使用第二个元素,例如:
$result=($date-split'-')[1]
它可能也比正则表达式快(还没有测量)。有几种替代方法
$date = 'ALL2-20210301-XXXXXX-XXXXX_X'
$date.Split('-')[1]
$date -split '-' | Select-Object -Index 1
$date -replace '^.+?-|-.+$'
$date -replace '.+(\d{8}).+','$1'
[regex]::Match($date,'\d{8}').Value
if($date -match '\d{8}'){$matches.0}
几种替代方法
$date = 'ALL2-20210301-XXXXXX-XXXXX_X'
$date.Split('-')[1]
$date -split '-' | Select-Object -Index 1
$date -replace '^.+?-|-.+$'
$date -replace '.+(\d{8}).+','$1'
[regex]::Match($date,'\d{8}').Value
if($date -match '\d{8}'){$matches.0}