regexp_replace() [noindex] thing

Started by Marcus Engeneover 17 years ago3 messagesgeneral
Jump to latest
#1Marcus Engene
mengpg2@engene.se

Hi!

I'm using tsearch2 and sometimes there are blocks of text that shouldn't
be indexed.

There is a trigger function that gathers data from the usual suspects
and updates the index. in this trigger, I'd like to exclude thing in a
[noindex] tag:
select
regexp_replace
('innan[noindex]apa[/noindex]klas[noindex]banan[/noindex]',
'(\\\[noindex\\\])+.*?(\\\[/noindex\\\])+',
' ')
I would like to have a function like the above that returns "innan klas"
for this data. I would have expected it to as I use the non greedy version.

Could someone please point me in the general direction here?

Best regards,
Marcus

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Marcus Engene (#1)
Re: regexp_replace() [noindex] thing

Marcus Engene <mengpg2@engene.se> writes:

I would like to have a function like the above that returns "innan klas"
for this data. I would have expected it to as I use the non greedy version.

regression=# select
regexp_replace
('innan[noindex]apa[/noindex]klas[noindex]banan[/noindex]',
'\\[noindex\\].*?\\[/noindex\\]',
' ', 'g');
regexp_replace
----------------
innan klas
(1 row)

regards, tom lane

#3Marcus Engene
mengpg2@engene.se
In reply to: Tom Lane (#2)
Re: regexp_replace() [noindex] thing

Tom Lane wrote:

Marcus Engene <mengpg2@engene.se> writes:

I would like to have a function like the above that returns "innan klas"
for this data. I would have expected it to as I use the non greedy version.

regression=# select
regexp_replace
('innan[noindex]apa[/noindex]klas[noindex]banan[/noindex]',
'\\[noindex\\].*?\\[/noindex\\]',
' ', 'g');
regexp_replace
----------------
innan klas
(1 row)

Super!

Best regards,
Marcus