Perl 多个正则匹配

时间:2021-04-25 09:42:04
#$_='{"code":0,"data":{"country":"*","country_id":"TW","area":"","area _id":"","region":"*省","region_id":"TW_01","city":"","city_id":"","county":"" ,"county_id":"","isp":"","isp_id":"-1","ip":"125.227.116.234"}}';
$_='{"code":0,"data":{"country":"中国","country_id":"CN","area":"华东","area_id":"300000","region":"浙江省","region_id":"330000","city":"湖州市","city_id":"330500","county":"","county_id":"-1","isp":"电信","isp_id":"100017","ip":"125.125.131.158"}}';
if ($_ =~ /(.*?)"region":(.*?),"region_id"(.*?)"city":(.*?),(.*?)/){
$a = $2;
$b = $4;
$a =~ s/"//g ;
$b =~ s/"//g ;
if ($b ){$city = $b;}else{
$city = $a;};
$city =~ s/"//g ;
print "\$city is $city\n";
}