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

If I want to match a string of the from "var=value", where var needs to be case-insensitive, but the value stuff needs to be treated case-sensitive, it strikes me that current support for this is rather poor.

I realize that I can do this.
print "OK" if m:[Vv][Aa][Rr]=/bin:;
The (?i) construct seems to affect the entire RE. Is there some more limited way to say that only a this portion of the RE should be case-insensitive?

Replies are listed 'Best First'.
Re: RegExps that are only partly case-insensitive
by ZZamboni (Curate) on Sep 06, 2000 at 18:20 UTC
    You almost gave the answer yourself. The (?i:...) construct can be used to "cloister" (?) the modifiers. Try this:
    % perl -ne 'print +(/(?i:var)=value/)?"Ok\n":"Not Ok\n"' var=value Ok Var=value Ok var=Value Not Ok VaR=value Ok VaR=valuE Not Ok

    --ZZamboni

      I don't find (?i:) documented in my Camel(2ed) book. Is that new? If I missed it completely, can you give me a page reference?
        Camel 2 is about 5.003. That feature wasn't added until 5.005. Camel 3 documents something kindof like 5.6.1, which isn't out yet. (There are a few places in the camel that document what 5.6 should become. :)

        -- Randal L. Schwartz, Perl hacker

Re (tilly) 1: RegExps that are only partly case-insensitive
by tilly (Archbishop) on Sep 06, 2000 at 18:22 UTC
    Two methods.
    print "OK" if m((?i:var)=/bin);
    and
    my $m_var = qr/var/i; print "OK" if m($m_var=/bin);
    The first is faster for building one RE. The second if you need a series of them.
Re: RegExps that are only partly case-insensitive
by Maqs (Deacon) on Sep 06, 2000 at 20:30 UTC
Re: RegExps that are only partly case-insensitive
by Maqs (Deacon) on Sep 06, 2000 at 20:41 UTC
    what about:
    print OK if lc($var)="/bin";
    Update: seems i didnt understand the question really :) Forget that answer

    /Maqs.