in reply to Regexes for Case Change
One way to do this is the code below. It goes through the string finding a word boundary followed by a series of word-characters and another word boundary and replaces it with the lcfirst'ed version of the word.
Another way would be to match on \b\w and replace with the lowercased version of the letter. To me though this version seems more readable. The other version may well be more efficient, but I think that's a question for the benchmarkers.
#!/usr/bin/perl -w use strict; my $test = "This Is A [Big] [Nasty Old] [Test]"; $test =~ s/\b(\w+)\b/lcfirst $1/eg; print $test;
Update: Okay, with the odd formatting I misread things as needing uppercasing.. fixed now though. If you're just trying to reduce everything to lowercase though just use 'lc $test'- It's quicker, easier, and does exactly what it says on the tin.
|
|---|