in reply to Get regexp modifiers
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... ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Get regexp modifiers
by ikegami (Patriarch) on Jan 06, 2010 at 02:15 UTC | |
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 |