in reply to Quick regexp question

$a =~ s{\b([A-Z]{4,})\b}{ucfirst(lc($1))}eg; ^^^ slash removed
You realize of course that there many other (probably better) ways to do this. Particularly, I wonder why you would need the \b, as [A-Z]{4,} is greedy and will take whole words on a match. And then there is of course the \L escape sequence. I would probably have done it like this:
$a =~ s#([A-Z])([A-Z]{3,})#$1\L$2\E#g;

Liz

Replies are listed 'Best First'.
Re: Re: Quick regexp question
by bart (Canon) on Oct 05, 2003 at 14:01 UTC
    If you're going to better him on his code, you might just as well do it the proper way. Eh... the shorter way. :)
    $a =~ s#([A-Z]{4,})#\u\L$1#g;
      To be honest, I didn't know you could chain \u\L that way.

      Another "nice idiom learned at the Monastery" for me today!

      Thanks, bart!

      Liz

Re: Quick regexp question
by Abigail-II (Bishop) on Oct 05, 2003 at 22:01 UTC
    Without the \b, you'd change fooBARBAZ into fooBarbaz. With the \b, you'd leave it unmodified.

    Abigail