in reply to RegEx Problem

s/\B([A-Z])(?=[a-z])/-\l$1/g; # ?

Although if you can guarantee that a capital letter will never occur at the beginning of the string and will always denote a new word (ie, samIAm), you can simplify that to just...

s/([A-Z])/-\l$1/g;

    --k.


Replies are listed 'Best First'.
Re: Re: RegEx Problem
by L0rdPhi1 (Sexton) on May 29, 2002 at 00:54 UTC
    I'm currently using:
    $moo = 'boo-hoo-hoo'; $hoo = lcfirst join '', map { ucfirst $_ } split /-/, $moo;
    To do that exact reverse of the above... is there a better way (I'm sure there is)?

      Ah, I should be able to redeem myself on this one...

      $str =~ s/-([a-z])/uc $1/ge;

      /me crosses fingers

      Update: Oh dang. Damn you, Kanji ;)

        I prefer to save /e for more complex substitutions, as \u (\l's counterpart) will do the same job...

        s/-([a-z])/\u$1/g;

            --k.