snafu has asked for the wisdom of the Perl Monks concerning the following question:

I have been reading some stuff on RE's but have never seen this question answered. Are multiple modifiers allowed in RE's?

I did some experimenting and it looks like they are allowed to some extent but I did get errors whenever I tried m//gce or m//ecg (Perl threw a bareword exception). I would think that allowing more than one modifier would be a good thing. Anyone else experimented with this before?

----------
- Jim

Replies are listed 'Best First'.
Re: RE's and multiple modifiers...
by lestrrat (Deacon) on Sep 28, 2001 at 02:14 UTC

    both s/// and m// allow multiple modifiers. it's just that /e is not supported for m// :-)

    For cool usage of multipler modifiers, you should see the quintessential JAPH that's mentioned in the end of this column by none other than merlyn

(crazyinsomniac) Re: RE's and multiple modifiers...
by crazyinsomniac (Prior) on Sep 28, 2001 at 04:33 UTC
    um yeah, perlop say which switches are available to the "Regexp Quote-Like Operators".

    Furthermore, not only are multiple modifiers allowed in Regular Expressions, but with "Extended" regular expressions, those modifiers can be applied to "parts" of regular expressions, like:

    #!/usr/bin/perl -w use strict; # 0 0 1 0 1 my @words = qw, eLBow ElBow elBoW eLbow elboW,; # I want to match all words elbow # whose W is capital, and e and o e are in lower case # and but l and B can be either case # There are two ways to do it for(@words) { printf "%s\n",$_ if /e(L|l)(B|b)oW/; } ##or using Extended Regular Expressions for(@words) { printf "%s\n",$_ if /e(?i-:lb)oW/; } __END__ # the output elBoW elboW elBoW elboW
    Now that is cool.

     
    ___crazyinsomniac_______________________________________
    Disclaimer: Don't blame. It came from inside the void

    perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Re: RE's and multiple modifiers...
by Flame (Deacon) on Sep 28, 2001 at 01:58 UTC
    I can't say for sure, but the 'e' modifier doesn't seem to apply in m// according to a table in Programming Perl (Third Edition).


    "Wierd things happen, get used to it"

    Flame ~ Lead Programmer: GMS
    http://gms.uoe.org