public inbox for [email protected]  
help / color / mirror / Atom feed
From: jian he <[email protected]>
To: Chris Hoover <[email protected]>
Cc: [email protected]
Subject: Re: Regexp_replace help
Date: Fri, 13 Sep 2024 09:14:51 +0800
Message-ID: <CACJufxELF8JF=HazRv1r-zYTvLog6vDjwo8wsgpT6K0xdQ_jWw@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

On Fri, Sep 13, 2024 at 5:18 AM Chris Hoover <[email protected]> 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 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’
>

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+)');






view thread (3+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Regexp_replace help
  In-Reply-To: <CACJufxELF8JF=HazRv1r-zYTvLog6vDjwo8wsgpT6K0xdQ_jWw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox