Perl相当于PHP的preg_callback

Jos*_*eph 8 php regex perl

我们在Perl中有一个preg_callback等价物吗?

让我们说我想匹配一些东西,并用匹配的东西调用的函数的返回值替换它.

YOU*_*YOU 17

使用s///e- 评估修饰符,你可以在第二部分放置任意perl代码.

$x = "this is a test";
$x =~ s/(test)/reverse($1)/eg;
print $x;

//this is a tset
Run Code Online (Sandbox Code Playgroud)

参考:http://perldoc.perl.org/perlretut.html#Search-and-replace