Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 排除正则表达式(regex)从XML获取的参数_Powershell - Fatal编程技术网

Powershell 排除正则表达式(regex)从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

我在XML文件中有一个带掩码的参数:

<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}