Powershell子串切割

1 string powershell substring

Powershell中是否有一个函数可以根据给定的格式化掩码减少值?

让我们使用例如 $test = "Value 14, Code 57"

Cut-Substring("Value $val, Code $code",$test)
Run Code Online (Sandbox Code Playgroud)

结果我想收到$val = 14$code = 57.

如果没有,是否有更强大的工具允许访问给定标签旁边的字段?

man*_*lds 5

嗯,正则表达式?

$test = "Value 14, Code 57"
$test -match 'Value (\d+), Code (\d+)'
$matches[1] #14
$matches[2] #57
Run Code Online (Sandbox Code Playgroud)

正则表达式的强大功能应该允许您根据自己的需要进行调整.