Ben*_*ard 31
另一种方法是使用operator -replace.
$teststring = "test=keep this, but not this."
$teststring -replace ".*=" -replace ",.*"
Run Code Online (Sandbox Code Playgroud)
.*= 表示任意数量的字符,包括等号.
,.* 表示逗号后跟任意数量的字符.
由于您基本上删除了字符串的这两部分,因此您不必指定用于替换它们的空字符串.您可以使用多个替换,但请记住订单是从左到右.
$a="some text =keep this,but not this"
$a.split('=')[1].split(',')[0]
Run Code Online (Sandbox Code Playgroud)
回报
keep this
Run Code Online (Sandbox Code Playgroud)