Is there a way to precompile a regex in Perl?

后端 未结 3 2101
刺人心
刺人心 2020-12-08 14:11

Is there a way to precompile a regex in Perl? I have one that I use many times in a program and it does not change between uses.

3条回答
  •  天命终不由人
    2020-12-08 14:57

    Simple: Check the qr// operator (documented in the perlop under Regexp Quote-Like Operators).

    my $regex = qr/foo\d/;
    $string =~ $regex;
    

提交回复
热议问题