public inbox for [email protected]
help / color / mirror / Atom feedRegexp_replace help
3+ messages / 3 participants
[nested] [flat]
* Regexp_replace help
@ 2024-09-12 21:18 Chris Hoover <[email protected]>
0 siblings, 2 replies; 3+ messages in thread
From: Chris Hoover @ 2024-09-12 21:18 UTC (permalink / raw)
To: [email protected]
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: [email protected]
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Regexp_replace help
@ 2024-09-12 21:22 David G. Johnston <[email protected]>
parent: Chris Hoover <[email protected]>
1 sibling, 0 replies; 3+ messages in thread
From: David G. Johnston @ 2024-09-12 21:22 UTC (permalink / raw)
To: Chris Hoover <[email protected]>; +Cc: [email protected] <[email protected]>
On Thursday, September 12, 2024, Chris Hoover <[email protected]> wrote:
>
> 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’
>
Probably easier to just regexp_match “^(.+?code\d+)\b”, and keep the
contents of group 1.
David J.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Regexp_replace help
@ 2024-09-13 01:14 jian he <[email protected]>
parent: Chris Hoover <[email protected]>
1 sibling, 0 replies; 3+ messages in thread
From: jian he @ 2024-09-13 01:14 UTC (permalink / raw)
To: Chris Hoover <[email protected]>; +Cc: [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+)');
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2024-09-13 01:14 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-09-12 21:18 Regexp_replace help Chris Hoover <[email protected]>
2024-09-12 21:22 ` David G. Johnston <[email protected]>
2024-09-13 01:14 ` jian he <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox