in reply to Re: help with a regexp
in thread help with a regexp

This soluction does work, but it does force all the letters inbetween the first and last to lowercase. If you want to leave them alone then you should use this:

#!/usr/bin/perl -wl use strict; my $foo="xoxoxoxoxoxoxoxoxoxoxoxoxoxoxox"; $foo =~ s/^(.)(.*)(.)$/\U$1\E$2\U$3/; print "$foo\n"; #Output: XoxoxoxoxoxoxoxoxoxoxoxoxoxoxoX my $bar="xoXOxoXOxoXOxoXOxoXOxoXOxo"; $bar =~ s/^(.)(.*)(.)$/\U$1\E$2\U$3/; print "$bar\n"; #Ooutput: XoXOxoXOxoXOxoXOxoXOxoXOxO

The original question was worded with what to do with the middle segment was up in the air. Just trying to add clarification for posterity :)

Replies are listed 'Best First'.
Re: Re: Re: help with a regexp
by sauoq (Abbot) on Sep 26, 2002 at 19:43 UTC

    Both your solution and husoft's fail on a single character string. As "x" consists of a single character and that character is both the first and the last it should be capitalized.

    -sauoq
    "My two cents aren't worth a dime.";