gpt4 book ai didi

regex - 这个数组的正则表达式是什么

转载 作者:行者123 更新时间:2023-12-01 09:06:14 25 4
gpt4 key购买 nike

假设我有这样的正文

["什么颜色",["Red","Blue","Green","Yellow","Brown","White"]]

匹配颜色的正则表达式是什么

我试试这个

 while ($mystring =~ m,/"(.*?)"/|,|[/"(.*?)"|,|/],g);
print "Your Color is : [$1]\n";

谁能帮我把这个 perl 脚本打印出来

 - Your Color is: Red - Your Color is: Blue - Your Color is: Green - Your Color is: Yellow - Your Color is: Brown - Your Color is: White

最佳答案

由于此文本是有效的 json 字符串,您可以使用 JSON 对其进行解析:

use JSON;  

my $json = '["What Color",["Red","Blue","Green","Yellow","Brown","White"]]';
print "- Your Color is: $_\n" for @{ decode_json($json)->[1] }

关于regex - 这个数组的正则表达式是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7132987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com