in reply to Get regexp modifiers

You can tell if the case-insensitive modifier was used pretty easily:

sub is_ci { my ($pat) = @_; my ($pos_mods) = $pat =~ /^\(\?(\w*)(?:-\w*)?:.*\)/s or return 0; return $pos_mods =~ /i/; }

Or even the following in Perl ≥ 5.10:

use re qw( regexp_pattern ); sub is_ci { (regexp_pattern(shift))[1] =~ /i/ }

But you can't tell if a pattern is case-sensitive or not.

The following will all come up as case-sensitive even though they're not:

qr/(?i:hello)/ qr/(?i)hello/ qr/[hH][eE][lL][lL][oO]/ qr/1234/

The following will all come up as case-insensitive even though they're not:

qr/(?-i)hello/i qr/(?-i:hello)/i qr/he(?-i:l)lo/i

Update Forgot to escape ? in my pattern. Fixed.

Replies are listed 'Best First'.
Re^2: Get regexp modifiers
by KSURi (Monk) on Jan 06, 2010 at 11:26 UTC
    Nice! Thank you.