Count the capture groups in a qr regex?

后端 未结 3 666
庸人自扰
庸人自扰 2021-01-04 13:40

I am working on a project which at one point gets a list of files from an ftp server. At that point it either returns an arrayref of files OR if an optional regex reference

3条回答
  •  粉色の甜心
    2021-01-04 14:34

    You could use something like:

    sub capturing_groups{
        my $re = shift;
        "" =~ /|$re/;
        return $#+;
    }
    
    say capturing_groups qr/fo(.)b(..)/;
    

    Output:

    2
    

提交回复
热议问题