简体   繁体   English

编号正则表达式捕获的最大数量是多少?

[英]What's the maximum number of numbered regex captures?

I'm maintaining some code that reads values over a serial radio and unpacks them into Perl data structures: 我正在维护一些通过串行无线电读取值的代码,并将它们解压缩到Perl数据结构中:

# Don't yell at me, I didn't write this
if ($command_string =~
    /^.(.)(.).(..)(.)(..)(.)(....)(....)(....)(....)
        (..)(..)(.)(.)(.)(.)(..)(..)(..)(..)(..)(..)(.)(.).......
            (.)........(.)(.).*/sx) {

    $config->{sequence}      = hex(unpack('H2', $1));
    $config->{radio_id}      = hex(unpack('H2', $2));
    ...
    $config->{radio_type}    = hex(unpack('H2', $26));
    $config->{radio_channel} = hex(unpack('H2', $27));
}

This unwieldy capturing regex made me wonder: what's the upper bound on numbered capture variables in Perl? 这个笨重的捕获正则表达式让我想知道:Perl中编号捕获变量的上限是什么? Does it go all the way up to $MAXINT ? 它会一直到$MAXINT吗?

This script works up to at least $N=5000000 . 此脚本至少$N=5000000 After that, it runs out of memory. 之后,它耗尽了内存。

$N = $ARGV[0] || 5000;
$q = '(.)' x $N;
$regex = qr/$q/;
("x" x $N) =~ $regex;
print eval "\$$N";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM