Click here to get back home

Regular Expression to Replace UPPER Case Text with lower case text

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Regular Expression to Replace UPPER Case Text with lower case text penny 02-17-2008
Get Chitika Premium
Posted by penny on February 17, 2008, 9:42 pm
Please log in for more thread options
Is there a way in Regular Expressions to convert a string that is all
in upper case - and replace it with it's lower case equivalent?

I can do something like ([A-Z][A-Z]+\x?) to match any given word and
reference it as , however without using programming language lcase
or LOWER functions on it - how can I use reg ex to convert the text to
it's lower case equivalent??


Thanks - (I use coldfusion but the regular expression syntax is
similar)

Posted by Gunnar Hjalmarsson on February 17, 2008, 10:11 pm
Please log in for more thread options
penny wrote:
> Is there a way in Regular Expressions to convert a string that is all
> in upper case - and replace it with it's lower case equivalent?
>
> I can do something like ([A-Z][A-Z]+\x?) to match any given word and
> reference it as , however without using programming language lcase
> or LOWER functions on it - how can I use reg ex to convert the text to
> it's lower case equivalent??

You can't. Regular expressions match or don't match. To change the
contents of a string, you need functions or operators (such as the s///
operator).

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Posted by RK_78 on February 18, 2008, 9:34 am
Please log in for more thread options
> Is there a way in Regular Expressions to convert a string that is all
> in upper case - and replace it with it's lower case equivalent?
>
> I can do something like ([A-Z][A-Z]+\x?) to match any given word and
> reference it as , however without using programming language lcase
> or LOWER functions on it - how can I use reg ex to convert the text to
> it's lower case equivalent??
>
> Thanks - (I use coldfusion but the regular expression syntax is
> similar)

Hi Penny ;

Try This

my $InFile=$ARGV[0] || die("**ERROR** -> Usage: $0 InputFile
OutputFile \n");
my $OutFile=$ARGV[1] || die("**ERROR** -> Usage: $0 InputFile
OutputFile \n");

open(INFILE,"< $InFile") || die "cannot open $InFile : $!"; # $!
Stores the error message
open(OUTFILE,"> $OutFile") || die "cannot open $OutFile : $!";

my $line;

while ($line=<INFILE>) {
        $line =~ tr/A-Z/a-z/;
        printf(OUTFILE $line);
}

close(INFILE);
close(OUTFILE);



The key point here is the tr/// transliteration operator.

Better ideas folks ?

Riad.

Posted by ccc31807 on February 18, 2008, 10:49 am
Please log in for more thread options
> Better ideas folks ?

Ditch CF and use Perl.

;-)

CC

Posted by Tad J McClellan on February 18, 2008, 5:31 pm
Please log in for more thread options
>> Better ideas folks ?
>
> Ditch CF and use Perl.


What, and get laughed at?


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Similar ThreadsPosted
Regular expression weirdness with upper and lower case December 6, 2004, 12:26 pm
regex upper and lower case April 20, 2007, 8:40 am
how to substitute text - special case February 20, 2008, 5:54 pm
FAQ: How do I substitute case insensitively on the LHS while preserving case on the RHS? October 17, 2004, 11:10 am
FAQ: How do I substitute case insensitively on the LHS while preserving case on the RHS? October 17, 2004, 5:10 pm
FAQ 6.5 How do I substitute case insensitively on the LHS while preserving case on the RHS? February 25, 2005, 12:03 pm
FAQ 6.5 How do I substitute case insensitively on the LHS while preserving case on the RHS? April 9, 2005, 11:03 am
FAQ 6.5 How do I substitute case insensitively on the LHS while preserving case on the RHS? June 25, 2005, 5:03 pm
FAQ 6.5 How do I substitute case insensitively on the LHS while preserving case on the RHS? October 20, 2005, 4:03 pm
FAQ 6.5 How do I substitute case insensitively on the LHS while preserving case on the RHS? December 13, 2005, 5:03 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap