Regexp_replace help

From: Chris Hoover <chrish(at)aweber(dot)com>
To: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Regexp_replace help
Date: 2024-09-12 21:18:30
Message-ID: 18A99BB3-EB26-47A3-94D6-D951E984D982@aweber.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Looking for some help here. I have a string that has ‘code1234’ in it. The 1234 can vary and I won’t know what they would be. Trying to figure out how to use regexp_replace to trim down the string, but unsure how to keep the ‘code1234’ in the string.

The search should be ‘ code[0-9]+? .*’. However, I don’t understand what the replace should be.

I.E.:
SELECT regexp_replace(’This is my test string that caused code12 from abc’,
‘ code[0-9]+? .*’,
‘What should this be so I keep the code12?‘)
Desire result:
’This is my test string that caused code12’

SELECT regexp_replace(’This is my second test string and it is causing code1234 from def. The weather is nice. :)’,
‘ code[0-9]+? .*’,
‘What should this be so I keep the code1234?’)
Desire result:
‘This is my second test string and it is causing code1234’

Thanks,

Chris Hoover
Senior DBA
AWeber.com
Cell: (803) 528-2269
Email: chrish(at)aweber(dot)com

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message David G. Johnston 2024-09-12 21:22:54 Re: Regexp_replace help
Previous Message Henry Ashu 2024-09-12 17:07:43 is the oracle client supposed to be owned by postgres or root?