in reply to Re: Get regexp modifiers
in thread Get regexp modifiers
I think ref($check_re) ne 'Regexp' can fail in modern Perls. You want to use
Or if you want to support Perl < 5.10,use re qw( is_regexp ); is_regexp($check_re)
BEGIN { eval 'use re qw( is_regexp )'; if (!defined(&is_regexp)) { my $re_class = ref qr//; *is_regexp = sub($) { local *__ANON__ = 'is_regexp'; return UNIVERSAL::isa($_[0], $re_class); }; } } is_regexp($check_re)
That said, I don't think you should be checking if it's a compiled regex pattern at all. Just checking if it looks like one (as I did) is much more tolerant.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Get regexp modifiers
by afoken (Chancellor) on Jan 06, 2010 at 09:34 UTC | |
by ikegami (Patriarch) on Jan 06, 2010 at 16:01 UTC | |
by afoken (Chancellor) on Jan 07, 2010 at 10:11 UTC | |
by ikegami (Patriarch) on Jan 07, 2010 at 16:25 UTC |