How to introspect regexes in the Perl API

前端 未结 2 588

I\'m working on some code that needs to serialize Perl regexes, including any regex flags. Only a subset of flags are supported, so I need to detect when unsupported flags like

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-20 05:46

    use Data::Dump::Streamer ':util';
    my ($pattern, $flags) = regex( qr/foo/i );
    print "pattern: $pattern, flags: $flags\n";
    # pattern: foo, flags: i
    

    But if you are trying to restrict more recent features, you have a lot more work to do than just checking for /u.

提交回复
热议问题