At 13:39 +0300 12/04/2011, Shlomit Afgin wrote:
I need to write regular expression that will capitalize the first
letter of each word in the string.
Word should be word that her length 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;
but it not working so well.
Why not just keep it simple so that you don't need to spend ten
minutes working out what the regex means next time you look at the
code.
#!/usr/local/bin/perl
use strict;
$_ = "jack and jill went up the hill to fetch a pail of water";
s~\w{3,}~\u$&~g;
s~\band\b~\l$&~ig;
s~\bthe\b~\l$&~ig;
print;
JD
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/