I've got the gut-feeling, that this is bad advice and there's a better way to do it... but the following works here...
HTHuse strict; # print RE into variable and examine it... sub is_ci { my $check_re = shift; die "$check_re is not a RE" if ref $check_re ne 'Regexp'; open my $redir , '>', \my $output; print $redir $check_re; close $redir; return $output =~ /i.*?\-/; # i before '-' } my $r1 = qr/hello/i; my $r2 = qr/hello/; print "true is " , is_ci($r1) ? 'true' : 'false' , " ?\n"; # true print "false is " , is_ci($r2) ? 'true' : 'false' , " ?\n"; # false print "false is " , is_ci(\"nonsense") ? 'true' : 'false' , " ?\n"; # + die!
Update: Ah trustworthy guts ;-) See ikegamis response below...
Reading this thread, I second what ww questions here - if one needs to check regexp modifiers a posteriori, that seems to be an indicator for a design problem. But maybe the regexp comes from user input... ?
In reply to Re: Get regexp modifiers
by Perlbotics
in thread Get regexp modifiers
by KSURi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |