1252748
1252748

Reputation: 15372

Postgres regex to uppercase

How can I use regex in Postgres to replace a capture with an upper case version of itself.

regexp_replace(pf.description, '^(.)(.*)$', '\U\1\E\2', 'gi') as description

is giving me the string back with the literal values \U and \E.

Upvotes: 2

Views: 3848

Answers (1)

Erwin Brandstetter
Erwin Brandstetter

Reputation: 656616

There is no built-in regex functionality in Postgres to convert to upper / lower case (that I'd know of).

I would use left() and right() instead:

SELECT upper(left('test_string', 1))
    || lower(right('test_string', -1));

Result:

Test_string

Postgres regular expression functionality in the manual.

Upvotes: 4

Related Questions