我的变量中有一些数据,那么如何在powershell中剪切第一个字段并将输出作为第二个字段。
PS D:\Testing_PowerShell_Script> $content (显示可变内容)
"title": "myname",
"title": "othername", (这是内容变量具有的数据。)
现在,我想要剪切"title":filed,并在powershell中获得仅为myname的输出,而不是双引号和逗号。请帮帮忙
发布于 2019-08-05 17:40:01
您可以使用带有Select-String的简单正则表达式模式来获取"title":后面引号中的所有内容
$titles = $content |Select-String '"title": "([^"]+)"' -AllMatches |Select-Object -Expand Matches |ForEach-Object {$_.Groups[1].Value}$titles现在是由两个字符串myname和othername组成的数组
发布于 2019-08-05 17:49:22
试试这个:你可以直接得到不带引号的值列表
$t = '"title": "myname",
"qqqq": "othername",'
$t -split "," | %{ ($_ -split ":")[1] -replace "`"","" }https://stackoverflow.com/questions/57355757
复制相似问题