Re: Regexp_replace help - Mailing list pgsql-admin

From jian he
Subject Re: Regexp_replace help
Date
Msg-id CACJufxELF8JF=HazRv1r-zYTvLog6vDjwo8wsgpT6K0xdQ_jWw@mail.gmail.com
Whole thread Raw
In response to Regexp_replace help  (Chris Hoover <chrish@aweber.com>)
List pgsql-admin
On Fri, Sep 13, 2024 at 5:18 AM Chris Hoover <chrish@aweber.com> wrote:
>
> 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
wouldbe.  Trying to figure out how to use regexp_replace to trim down the string, but unsure how to keep the ‘code1234’
inthe 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’
>

please try these.

select SUBSTRING($$This is my test string that caused code12 from
abc$$ from '.*(?:code[0-9]\S+)');
select SUBSTRING($$This is my test string that caused code12s1 from
abc$$ from '.*(?:code\S+)');
SELECT SUBSTRING($$This is my second test string and it is causing
code1234 from def.  The weather is nice. :$$
from '.*(?:code\S+)');



pgsql-admin by date:

Previous
From: Wells Oliver
Date:
Subject: Re: Query plan getting less efficient over time with frequent updates and deletes..
Next
From:
Date:
Subject: RE: is the oracle client supposed to be owned by postgres or root?