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...

use 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!
HTH

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.