Regular Expression to Replace UPPER Case Text with lower case text

P

penny

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 \1, 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)
 
G

Gunnar Hjalmarsson

penny said:
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 \1, 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).
 
G

Gunnar Hjalmarsson

Abigail said:
penny ([email protected]) wrote on VCCLXXXIV September MCMXCIII in
<URL:"" Thanks - (I use coldfusion but the regular expression syntax is
"" similar)

Oh, sure. Well, that could be a reason to avoid 'lc'. I guess your option
is to match each and every 'A', replace it with an 'a', match each and
every 'B', replace it with a 'b', etc. Hopefully, you don't have to many
different characters in your text.

tr/A-Z/a-z/

But there is of course a risk that ColdFusion doesn't have a tr///
operator either.
 
R

RK_78

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 \1, 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.
 
C

Charlton Wilbur

p> Is there a way in Regular Expressions to convert a string that
p> is all in upper case - and replace it with it's lower case
p> equivalent?

There's a very simple way in Perl, but it doesn't use a regular expression.

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

Then why aren't you asking in a ColdFusion newsgroup?

Charlton
 
P

penny

Thanks for all the replies - For those keeping Score at home:
Replace:
"([A-Z]){1}([[:upper:]]+)"
WITH:
"\1\L\2"

The reason I didn't go the CFusion newsgroup first is that CF runs
with a limited perl engine and I figured you guys would know more
about regex than the cf group (eek)

But turns out it can be done and very easily with one line of
REReplace.

The application is written in CF so - sorry- no chance of ditching
cf ;)

This is a back reference example and here is the Break Down:
First 'group' is the
([A-Z]){1} - This means exactly 1 Single Upper Case Character and the
() parenthesis is so that I can Reference this Match later in the
Replace with string as \1
([[:upper:]]+) - This means 1 or more upper case characters and the ()
parenthesis is so that I can reference this Match later as \2

Then I replace this string with
\1 - this means the 'first' match from my () group (which will be a
single upper case character)
\L\2 - Means the Rest of the String that I got from my second () match
above as \2 will be all LOWER case

Thanks
 
C

Charlton Wilbur

p> The reason I didn't go the CFusion newsgroup first is that CF
p> runs with a limited perl engine and I figured you guys would
p> know more about regex than the cf group (eek)

Er, no, while CF may have a PCRE library glommed into it somewhere, it
has no Perl content at all; and "Perl compatible" regular expressions aren't.

Charlton
 
C

Charlton Wilbur

T> What, and get laughed at?

Still much cheaper, and easier on the liver, than the high blood
pressure medication and antidepressants that go along with long-term
ColdFusion exposure.

Charlton
 
C

ccc31807

On Feb 18, 5:31 pm, Tad J McClellan
What, and get laughed at?

In the past eight years, I have been constructing web apps using a
variety of technologies, either by choice or because of stated
requirements, including Perl, CF, .NET, JSP, and Python. Recently,
under the influence of writings by Paul Graham and Slava Akhmechet, I
have developed a high degreee of interest in using Lisp. See the links
below.

Using Perl for web apps is controversial to say the least, and I can
sympathize with your little joke. You DO get laughed at if you use
Perl, and that's not a joke. However, Perl has some advantages over
these other technologies, as well as some disadvantages.

I understand that this is OT, but I'm just wondering ... Is there any
good reason I shouldn't learn how to develop web apps in Lisp? I'm
just now taking my first baby steps in constructing Lisp scripts that
spit out HTML with data drawn from data stores, and as far as I can
tell, Lisp potentially has some strengths that Perl does not have (or
CF, .NET, JSP, Python, or any of the others.)

CC

Links:
http://paulgraham.com/avg.html
http://lib.store.yahoo.net/lib/paulgraham/bbnexcerpts.txt
http://www.defmacro.org/ramblings/fp.html
http://www.defmacro.org/ramblings/continuations-web.html
 
J

Jürgen Exner

RK_78 said:
$line =~ tr/A-Z/a-z/;

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

How does A-Z or the tr/// expression for that matter handle non-English
letters?
What about upper case letters that don't have a corresponding lower case
letter? I don't know if such a letter exists. It does for the other
direction, e.g. the Geman sharp s (ß) which is capitalized as double "SS".
Example: Straße ==> STRASSE

Similar examples exist in other languages

I cannot imagine that this tr/// expression will handle these correctly.

jue
 
C

Charlton Wilbur

cc> Using Perl for web apps is controversial to say the least, and
cc> I can sympathize with your little joke. You DO get laughed at
cc> if you use Perl, and that's not a joke. However, Perl has some
cc> advantages over these other technologies, as well as some
cc> disadvantages.

Over the past 15 years, I've been involved in a variety of online
endeavors, including a significant amount of web software development.
The notion that using Perl for web apps is *controversial* is,
frankly, ludicrous.

What it boils down to is this: if you have competent developers who
choose the language and environment they work in on their technical
merits, your web application will work well. If you have incompetent
developers, or you choose the language and environment based on
marketing or managers' perceptions rather than technical merits, your
web application will not work well.

I have a whole series of anecdotes to illustrate this, but I'll leave
you with punch lines.

"We can't market anything based on Linux, who's heard of Linux? We'll
build it on Microsoft SQL Server instead." -- Project was 200% over
schedule and 300% over budget before the Microsoft plans were scrapped.

"We can't use Ruby on Rails for this. Who takes something with a name
like that seriously?" -- Company is foundering, after spending ~ $1
million patching a broken system instead of replacing it, because the
quoted manager was too risk averse to try an agile framework and
didn't have the budget to hire 20 Java monkeys for the approved
corporate approach.

"Perl can't do this, so I've given it to the Java consultants." --
The team of a dozen Java consultants (who were not so much
*incompetent* as *self-interested*, and were thus more interested in
stretching out the contract as long as possible) took 6 months to
deliver the specified application, which was irrelevant by then as I
had taken a week of downtime to solve that particular problem and four
others.

The person who laughs at you for using Perl is the person you will
leave in your dust, assuming you don't heed his advice.

cc> I understand that this is OT, but I'm just wondering ... Is
cc> there any good reason I shouldn't learn how to develop web
cc> apps in Lisp? I'm just now taking my first baby steps in
cc> constructing Lisp scripts that spit out HTML with data drawn
cc> from data stores, and as far as I can tell, Lisp potentially
cc> has some strengths that Perl does not have (or CF, .NET, JSP,
cc> Python, or any of the others.)

From a technical point of view, there's no reason to avoid Lisp in web
development. From a practical point of view, if you ever intend to
hand this code off to someone else or to work with someone else,
you'll need to find a Lisp enthusiast.

And any theoretical strengths Lisp might have once had have long since
been stolen by other languages; the practical ones, well, let's just
say that the common criticism of Perl, that it's possible to write
write-only code, is multiplied a thousandfold when you start dealing
with Lisp's macro system. And then, on top of that, you have the
rabid Lisp fanbase -- their own worst enemy.

But hey, good luck with that.

Charlton
 
C

ccc31807

On Feb 19, 1:35 pm, Charlton Wilbur
The notion that using Perl for web apps is *controversial* is,
frankly, ludicrous.

'Controversial' in the sense of causing controversary. As your own
punch lines demonstrate. Suffice it to say that people have strong
opinions about the (un)suitability of Perl for web apps, or any other
kind of apps for that matter.
The person who laughs at you for using Perl is the person you will
leave in your dust, assuming you don't heed his advice.

Just got back to work after several hours out of the office and had my
ears filled with the INSTR() function in Access. Seems that they
needed to match two rather large text files with 'MTH-1101' in one
file with 'MTH1101' in the other file, and ended up using Access to
match the rows. Yeah, I hear you!
From a technical point of view, there's no reason to avoid Lisp in web
development. From a practical point of view, if you ever intend to
hand this code off to someone else or to work with someone else,
you'll need to find a Lisp enthusiast.

Same with Perl, as my course matching story demonstrates.
And any theoretical strengths Lisp might have once had have long since
been stolen by other languages; the practical ones, well, let's just
say that the common criticism of Perl, that it's possible to write
write-only code, is multiplied a thousandfold when you start dealing
with Lisp's macro system. And then, on top of that, you have the
rabid Lisp fanbase -- their own worst enemy.

Agree with every thing you said, except that Lisp, like Perl and other
technologies, has tasks for which it is suited. Those rabid fans? Just
because they are rabid doesn't mean that everything they claim is
false.

CC
 
J

Joost Diepenmaat

ccc31807 said:
I understand that this is OT, but I'm just wondering ... Is there any
good reason I shouldn't learn how to develop web apps in Lisp? I'm
just now taking my first baby steps in constructing Lisp scripts that
spit out HTML with data drawn from data stores, and as far as I can
tell, Lisp potentially has some strengths that Perl does not have (or
CF, .NET, JSP, Python, or any of the others.)

Lisp is a great language to develop in, so why not? You may have to
spend more time to find (and possibly fix) the right mix of libraries to
use for web apps but there is a lot of interesting web stuff going on in
the Lisp world.

http://www.lispcast.com/ has some interesting videos (the code is all
pretty low-level, though - there are much more comple CL web / model
frameworks out there).
 
M

Martijn Lievaart

How does A-Z or the tr/// expression for that matter handle non-English
letters?
What about upper case letters that don't have a corresponding lower case
letter? I don't know if such a letter exists. It does for the other
direction, e.g. the Geman sharp s (ß) which is capitalized as double
"SS". Example: Straße ==> STRASSE

Similar examples exist in other languages

I cannot imagine that this tr/// expression will handle these correctly.

In fact, perldoc perlop warns for this and tells you to use lc.

M4
 
C

ccc31807

Errr, it was _your_ little joke.

You're right, I had forgotten I said that. But like all jokes, it
contains a grain of truth. My city has three big IT concentrattions,
in banking, insurance, and the military. In the first two, the
developers are divided into the Java and .NET camps. I occasionally
attend one of the various user group meetings that these people
frequent, and on occassion participate in the discussion. I remember
at least once when discussing the conversion of a bank's records (that
were presented as CSV files) I suggested that Perl might do well at
the conversion, which was met (litteraly) by guffaws. "You're simply
joking, everybody knows that Perl can't take a file, change a few
things, and write it out to another file, you've got to use a serious
language for that kind of job, like Java or Visual Basic."

I have found by experience that journeyman programmers, at least in my
city, regard Perl as a joke, unable to do anything serious. Of course,
they don't know the language, and typically they have the philosophy
that you should know only one language and know it well, otherwise you
will merely be confused. Some project managers have told me, using
these words, that they wouldn't hire any programmer that knew more
than one language. And this is at a company that yesterday had a share
price of $62.65 on a volume of 2,329,871. Managers have asked me
several different times, "Why use Perl when you can use ColdFusion?"
as if to say, "Why use an axe when you have a chainsaw handy?" The
perception here is that ColdFusion is a capable technology while Perl
is not.

In Paul Graham's essay 'Beating the Average' he claims that his
success was due to his choice of technology. I think that he is wrong,
but believe that the choice of a technology can be one very important
factor of success (others might be a growing market, customer service,
lots of hard work, and a bit of luck.)

I recently did an analysis of the employment postings for nine
different languages. Here are some raw numbers:
Java ~15,400 - 20,400
..NET ~10,000 - 15,000
C/C++ ~ 8,000 - 12,000
Perl ~ 6,000 - 8,000

By contrast, CF was around 300 and Lisp was around zero. I know that
the numbers of open positions doesn't mean much, but it's at least a
rough gauge of visibility of different languages among employers. In
my area, the only two players are Java and .NET (except the military,
actually the largest single employer, and they advertise for Ada, C/C+
+, and (yes) Perl programmers.) Also, there's quite a bit of COBOL
still left and one of the area colleges has a COBOL certificate
program.

For the reasons I have stated elsewhere, I am making a non-trivial
effort to learning Lisp. I expect that people will laugh at me for
this, as well.

CC
 
C

Charlton Wilbur

cc> I occasionally attend one of the various user group meetings
cc> that these people frequent, and on occassion participate in
cc> the discussion. I remember at least once when discussing the
cc> conversion of a bank's records (that were presented as CSV
cc> files) I suggested that Perl might do well at the conversion,
cc> which was met (litteraly) by guffaws. "You're simply joking,
cc> everybody knows that Perl can't take a file, change a few
cc> things, and write it out to another file, you've got to use a
cc> serious language for that kind of job, like Java or Visual
cc> Basic."

cc> I have found by experience that journeyman programmers, at
cc> least in my city, regard Perl as a joke, unable to do anything
cc> serious. Of course, they don't know the language, and
cc> typically they have the philosophy that you should know only
cc> one language and know it well, otherwise you will merely be
cc> confused. Some project managers have told me, using these
cc> words, that they wouldn't hire any programmer that knew more
cc> than one language.

So they're idiots. Why do you care about the opinions of idiots?

cc> I recently did an analysis of the employment postings for nine
cc> different languages. Here are some raw numbers:

.....that mean absolutely nothing. I've seen the same position
advertised over a dozen times because the hiring manager was
desperate, and contacted over a dozen recruiters; I've seen a dozen
positions in a company advertised with one ad.

To reiterate: you're putting up an elaborate rationalization to
justify that people who are demonstrably idiots are laughing at you,
as if the problem is Perl's. Consider, rather, that the problem is
*you*, in that you give far too much credence to the opinion of
idiots.

Charlton
 
C

ccc31807

cc> different languages. Here are some raw numbers:

....that mean absolutely nothing. I've seen the same position
advertised over a dozen times because the hiring manager was
desperate, and contacted over a dozen recruiters; I've seen a dozen

Not exactly. What these numbers represent are advertised positions. I
think they're correct to an order of magnitude. Don't you think that
there are more Java jobs than, say, Python jobs, and more Python jobs
than, say, Erlang jobs?
positions in a company advertised with one ad.

To reiterate: you're putting up an elaborate rationalization to
justify that people who are demonstrably idiots are laughing at you,
as if the problem is Perl's.

You have completely misunderstood what I said. The people I mentioned
are not idiots, they're simply ignorant. These people have well
paying, responsible jobs, but the jobs are MANAGEMENT jobs, not
technical or engineering jobs. Typically they have a business degree
with one course in VB and one course in SQL, and they are convinced
that they know everything there is to know about technology. Why?
Because their opinions have been validated again and again by real
world experience. Again, this is managerial and business experience,
not engineering or technical experience. These are bankers and
marketers and insurance executives, not programmers or software
engineers.

(Tuesday, I asked one of these if he was a vi man or an emacs man, and
he looked at me as if I were stark, raving mad. The ONLY IDE he has
ever heard of is Visual Studio.)
Consider, rather, that the problem is
*you*, in that you give far too much credence to the opinion of
idiots.

In the first place, they aren't idiots but middle and uppermid level
managers who have done well in their careers. In the second place, I
evangelize my beliefs, which basically are Perl and Python in a BSD or
Linux server connected to a Postgres or MySQL DB served up by Apache.

CC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top