Can I use named groups in a Perl regex to get the results in a hash?

后端 未结 4 2083
死守一世寂寞
死守一世寂寞 2020-12-30 00:12

Is it possible to perform a named-group match in Perl\'s regex syntax as with Python\'s? I always bind the $n values to proper names after matching, so I\'d fin

4条回答
  •  庸人自扰
    2020-12-30 00:45

    Perl uses (?pattern) to specify names captures. You have to use the %+ hash to retrieve them.

    $variable =~ /(?\d+)/;
    print "Count is $+{count}";
    

    This is only supported on Perl 5.10 and higher though.

提交回复
热议问题