I have values like this: 1ST, 2ND, FIRST, and I want to remove the 'ST' and 'ND' ONLY if what comes before is a digit.
I am running postgres 9.5 and I have a positive lookbehind working in SQL Fiddle but it only works on 9.6
SELECT ex,
regexp_replace(ex, '(?<=[0-9]+)(TH|ST|ND|RD)', '', 'gi') as test
FROM t1
Is there any other way to do this besides using a CASE statement like this:
SELECT ex,
(CASE WHEN ex ~ '\d(TH|ST|ND|RD)' THEN regexp_replace (ex, 'TH|ST|ND|RD', '','gi') ELSE ex end) as test_case
FROM t1
Any suggestions would be appreciated. Thanks!