From maechler at stat.math.ethz.ch  Tue Apr 14 17:51:16 2009
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Tue, 14 Apr 2009 17:51:16 +0200
Subject: [Rd] should sub(perl=TRUE) also handle \E in replacement,
	to complement \U and \L?
In-Reply-To: <77EB52C6DD32BA4D87471DCD70C8D70001075A06@NA-PA-VBE03.na.tibco.com>
References: <77EB52C6DD32BA4D87471DCD70C8D70001075A06@NA-PA-VBE03.na.tibco.com>
Message-ID: <18916.45300.570086.267927@lynne.math.ethz.ch>

>>>>> "WD" == William Dunlap <wdunlap at tibco.com>
>>>>>     on Mon, 13 Apr 2009 11:56:51 -0700 writes:

    WD> Currently sub(perl=TRUE) allows you to specify \U and \L
    WD> in the replacement argument so that the rest of the
    WD> subpatterns in the line (the \\<digit> things) will be
    WD> converted to upper or lower case, respectively.  perl
    WD> also also has a \E operator to end these case
    WD> conversions for the rest of the subpatterns (so they
    WD> retain whatever case they had in the original text).
    WD> For symmetry's sake I think it would be nice if R
    WD> supported that also.  E.g., to capitalize the first and
    WD> last letters of every word, leaving the case of the
    WD> interior letters alone, could be done with:

    >> gsub("(\\w)(\\w*)(\\w)", "\\U\\1\\E\\2\\U\\3", "useRs may
    >> fly into JFK
    WD> or laGuardia", perl=TRUE) [1] "UseRS MaY FlY IntO JFK OR
    WD> LaGuardiA"
    >> sub("(\\w)(\\w*)(\\w)", "\\U\\1\\E\\2\\U\\3", "useRs may
    >> fly into JFK
    WD> or laGuardia", perl=TRUE) [1] "UseRS may fly into JFK or
    WD> laGuardia"

    WD> A question regarding this came up in r-help today.

    WD> Bill Dunlap TIBCO Software Inc - Spotfire Division
    WD> wdunlap tibco.com

Thanks a lot, Bill, for your patch!

I have applied and committed it (after testing) to R-devel
[rev. 48321].

Best regards,
Martin Maechler, ETH Zurich



[Rd] should sub(perl=TRUE) also handle \E in replacement, to complement \U and \L?
Martin Maechler