Making substrings uppercase - Mailing list pgsql-general

From Oliver Kohll - Mailing Lists
Subject Making substrings uppercase
Date
Msg-id 85C3914E-5119-4332-81BD-5C4F0C9DB91E@gtwm.co.uk
Whole thread Raw
Responses Re: Making substrings uppercase  (David Johnston <polobo@yahoo.com>)
Re: Making substrings uppercase  (Alvaro Herrera <alvherre@2ndquadrant.com>)
List pgsql-general
Hello,

Given a string with certain words surrounded by stars, e.g.

The *quick* *brown* fox jumped over the *lazy* dog

can you transform the words surrounded by stars with uppercase versions, i.e.

The QUICK BROWN fox jumped over the LAZY dog

Given text in a column sentence in table sentences, I can mark/extract the words as follows:

SELECT regexp_replace(sentence,'\*(.*?)\*','STARTUPPER\1ENDUPPER','g') FROM sentences;

but my first attempt at uppercase transforms doesn't work:

select regexp_replace(sentence,'\*(.*?)\*','' || upper('\1'),'g') from sentences;

I thought of using substring() to split the parts up after replacing the stars with start and end markers, but that
wouldfail if there was more than one word starred. 

Any other ideas?

Oliver

pgsql-general by date:

Previous
From: 高健
Date:
Subject: PostgreSQL and cgroup
Next
From: Marc Mamin
Date:
Subject: Re: Sum of columns