agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFind and replace
4+ messages / 3 participants
[nested] [flat]
* Find and replace
@ 2019-09-11 20:24 Campbell, Lance <lance@illinois.edu>
2019-09-11 20:27 ` Re: Find and replace Rob Sargent <robjsargent@gmail.com>
2019-09-11 20:49 ` Re: Find and replace Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 4+ messages in thread
From: Campbell, Lance @ 2019-09-11 20:24 UTC (permalink / raw)
To: pgsql-sql
PostgreSQL 10.x
I don’t know the best way to do this. I need to do a find and replace in text fields. The value I need to find and replace may occur more than once in each field per record.
The value I am trying to match on:
Starts with a single { .
Ends with a single } .
In between these brackets can be the characters 0-9, a-z, A-Z, hyphens and underscores. But no spaces. These characters could be in any order.
The replacement value on a match is the same as what was found except for double {{ at the beginning and double }} at the end. Same values between the brackets as what was matched on.
Example:
{ab_1D3-4} becomes {{ab_1D3-4}}
Thanks for helping me with this.
Lance Campbell
University of Illinois
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Find and replace
2019-09-11 20:24 Find and replace Campbell, Lance <lance@illinois.edu>
@ 2019-09-11 20:27 ` Rob Sargent <robjsargent@gmail.com>
2019-09-11 20:31 ` Re: Find and replace Campbell, Lance <lance@illinois.edu>
1 sibling, 1 reply; 4+ messages in thread
From: Rob Sargent @ 2019-09-11 20:27 UTC (permalink / raw)
To: Campbell, Lance <lance@illinois.edu>; +Cc: pgsql-sql
> On Sep 11, 2019, at 2:24 PM, Campbell, Lance <lance@illinois.edu> wrote:
>
> PostgreSQL 10.x
>
> I don’t know the best way to do this. I need to do a find and replace in text fields. The value I need to find and replace may occur more than once in each field per record.
>
> The value I am trying to match on:
> Starts with a single { .
> Ends with a single } .
> In between these brackets can be the characters 0-9, a-z, A-Z, hyphens and underscores. But no spaces. These characters could be in any order.
> The replacement value on a match is the same as what was found except for double {{ at the beginning and double }} at the end. Same values between the brackets as what was matched on.
>
> Example:
> {ab_1D3-4} becomes {{ab_1D3-4}}
>
> Thanks for helping me with this.
>
> Lance Campbell
> University of Illinois
Are there curly braces which don’t start/end such strings? If not it might be easier to just double them up?
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Find and replace
2019-09-11 20:24 Find and replace Campbell, Lance <lance@illinois.edu>
2019-09-11 20:27 ` Re: Find and replace Rob Sargent <robjsargent@gmail.com>
@ 2019-09-11 20:31 ` Campbell, Lance <lance@illinois.edu>
0 siblings, 0 replies; 4+ messages in thread
From: Campbell, Lance @ 2019-09-11 20:31 UTC (permalink / raw)
To: Rob Sargent <robjsargent@gmail.com>; +Cc: pgsql-sql
I don’t think that is an option. The text I am doing the find and replace on contains CSS. I believe there will be squiggly brackets in the CSS. However, it should have spaces or carriage return line feeds between the brackets so there will not be any issues.
From: Rob Sargent <robjsargent@gmail.com>
Date: Wednesday, September 11, 2019 at 3:27 PM
To: Lance Campbell <lance@illinois.edu>
Cc: "pgsql-sql@postgresql.org" <pgsql-sql@postgresql.org>
Subject: Re: Find and replace
On Sep 11, 2019, at 2:24 PM, Campbell, Lance <lance@illinois.edu<mailto:lance@illinois.edu>> wrote:
PostgreSQL 10.x
I don’t know the best way to do this. I need to do a find and replace in text fields. The value I need to find and replace may occur more than once in each field per record.
The value I am trying to match on:
Starts with a single { .
Ends with a single } .
In between these brackets can be the characters 0-9, a-z, A-Z, hyphens and underscores. But no spaces. These characters could be in any order.
The replacement value on a match is the same as what was found except for double {{ at the beginning and double }} at the end. Same values between the brackets as what was matched on.
Example:
{ab_1D3-4} becomes {{ab_1D3-4}}
Thanks for helping me with this.
Lance Campbell
University of Illinois
Are there curly braces which don’t start/end such strings? If not it might be easier to just double them up?
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Find and replace
2019-09-11 20:24 Find and replace Campbell, Lance <lance@illinois.edu>
@ 2019-09-11 20:49 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 4+ messages in thread
From: Tom Lane @ 2019-09-11 20:49 UTC (permalink / raw)
To: Campbell, Lance <lance@illinois.edu>; +Cc: pgsql-sql
"Campbell, Lance" <lance@illinois.edu> writes:
> I don’t know the best way to do this. I need to do a find and replace in text fields. The value I need to find and replace may occur more than once in each field per record.
> The value I am trying to match on:
> Starts with a single { .
> Ends with a single } .
> In between these brackets can be the characters 0-9, a-z, A-Z, hyphens and underscores. But no spaces. These characters could be in any order.
> The replacement value on a match is the same as what was found except for double {{ at the beginning and double }} at the end. Same values between the brackets as what was matched on.
Sounds like a job for regular expressions.
regression=# select regexp_replace('abc{foo1}def{goo_bug}a', '{([-_a-zA-Z0-9]*)}', '{{\1}}', 'g');
regexp_replace
----------------------------
abc{{foo1}}def{{goo_bug}}a
(1 row)
See
https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2019-09-11 20:49 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-09-11 20:24 Find and replace Campbell, Lance <lance@illinois.edu>
2019-09-11 20:27 ` Rob Sargent <robjsargent@gmail.com>
2019-09-11 20:31 ` Campbell, Lance <lance@illinois.edu>
2019-09-11 20:49 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox