Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: RegEx Problem

by Kanji (Parson)
on May 29, 2002 at 00:38 UTC ( [id://169946]=note: print w/replies, xml ) Need Help??


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.


Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://169946]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-26 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found