Shlomit Afgin wrote:

Hi

Hello,

I need to write regular expression that will capitalize the first letter of 
each word in the string.
Word should be string with length that is greater or equal to 3 letters  
exclude the words 'and' and 'the'.

I tried:
$string = lc($string);
$string =~ s/\b(\w{3,}[(^the|^and)])\b/ucfirst($1)/ge;

[(^the|^and)] is a character class that matches *one* character, either '(' OR '^' OR '|' OR ')' OR 'a' OR 'd' OR 'e' OR 'h' OR 'n' OR 't'.


but it not working so well.

$ perl -le'
$_ = "I need to write regular expression that will capitalize the first letter";
print;
$_ = lc;
print;
s/(\S+)/\u$1/g;
print;
'
I need to write regular expression that will capitalize the first letter
i need to write regular expression that will capitalize the first letter
I Need To Write Regular Expression That Will Capitalize The First Letter



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to