On Nov 13, Ricardo Pichler said:

>I need replace in my string the characters in
>upperCase for the same but preceding the simbol +.
>
>$myName="RicardoPichler";
>s/.../.../g; # to do this return "+Ricardo+Pichler";
>
>$myName=~s/[A-Z]/\+[A-Z]/g;

You can't use a regex on the right-hand side of a s///, it's not
appropriate.  Instead, use capturing parentheses:

  $myName =~ s/([A-Z])/+$1/g;

Another way to do this, though, is to use a look-ahead:

  $myName =~ s/(?=[A-Z])/+/g;

That says "if we can look ahead and match an A-Z, then replace what we've
matched (which isn't anything, we've only LOOKED) with a +, for all
occurrences".

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to