我正在使用此代码通过正则表达式匹配来更改字符串。
$a->{'someone'} = "a _{person}";
$a->{'person'} = "gremlin";
$string = "_{someone} and a thing"
while($string =~ /(_\{(.*?)\}/g){
$search = metaquote($1);
$replace = $a->{$2};
$string =~ s/$search/$replace/;
}
结果是a _{person} and a thing
,但我期待:a gremlin and a thing
.
怎么做才能让它工作?