Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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
Regex 使用PowerShell和正则表达式解析文本_Regex_Powershell 5.0 - Fatal编程技术网

Regex 使用PowerShell和正则表达式解析文本

Regex 使用PowerShell和正则表达式解析文本,regex,powershell-5.0,Regex,Powershell 5.0,使用PowerShell和正则表达式分析文本: 查找“display\u name”:“elocin\u anagram”并输出elocin\u anagram。对所有“显示名称:…”重复上述步骤 你会怎么做 临时文件夹中不应存在名为1.txt的文件 # set-content of text file sc $env:temp\1.txt '_total":19,"subscriptions":[{"created_at":"2018-06-15T19:34:38Z","_id":"b7c42

使用PowerShell和正则表达式分析文本:

查找
“display\u name”:“elocin\u anagram”
并输出
elocin\u anagram
。对所有
“显示名称:…”
重复上述步骤

你会怎么做

临时文件夹中不应存在名为
1.txt
的文件

# set-content of text file
sc $env:temp\1.txt '_total":19,"subscriptions":[{"created_at":"2018-06-15T19:34:38Z","_id":"b7c42f6ce857162220e99533d3d6dc1ae11fac8d","sub_plan":"3000","sub_plan_name":"Channel Sub (❤ω❤)♡ ♡ ♡(elocin_anagram)","is_gift":false,"user":{"display_name":"elocin_anagram","type":"user","bio":"Games I like to play are VRChat, Beat Saber, Space Engineers, and Apex. I am also a certified Electronics Technician. You might see me make electronics and 3d model.","created_at":"2015-06-17T05:37:38Z","updated_at":"2020-05-11T05:51:58Z","name":"elocin_anagram","_id":"93742615","logo":"https://static-cdn.jtvnw.net/jtv_user_pictures/d37d128b-59b1-4015-9776-74866feb1d44-profile_image-300x300.png"},"sender":null},{"created_at":"2019-07-10T00:04:45Z","_id":"6a26c5a56b39d142a6e25ad30589a1b923fbc1bb","sub_plan":"1000","sub_plan_name":"Channel Sub(≧◡≦) ♡ (elocin_anagram) ","is_gift":false,"user":{"display_name":"LuckeaterVR","type":"user","bio":"","created_at":"2018-12-08T04:55:48Z","updated_at":"2020-04-24T01:44:56Z","name":"luckeatervr","_id":"00000","logo":"https://static-cdn.jtvnw.net/jtv_user_pictures/322ba52a-655c-42a4-8cc9-7b875debd5dd-profile_image-300x300.png"},"sender":null},{"created_at":"2020-01-16T01:23:17Z","_id":"17704f74767b5592c5fc221eca11a20579a8162c","sub_plan":"3000","sub_plan_name":"Channel Sub (❤ω❤)♡ ♡'
(gc $env:temp\1.txt | select-string '"display_name":"(.*?)"' -AllMatches).Matches.Value | % {$_ -match '"display_name":"(.*?)"' > $null; $matches[1]}
#
结果:

elocin_anagram
LuckeaterVR

如果使用具有正向后视功能的正则表达式,则可以大大简化代码:

gc $file |select-string '(?<="display_name":")[^"]+' -AllMatches | Select-Object -Expand Matches | %{ $_.Value }

gc$file | select string'(?您好,我不清楚您在问什么。@JPBlanc-代码复查或
(gc$env:temp\1.txt | select string'“display_name”:“(.*?”)-AllMatches.Matches |%{$_-match'“display_name:”(.*?”>$null;$Matches[1]