Search Postgresql Archives

replace inside regexp_replace

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have some text

'here is [[my text]] to replace and [[some more]]'

which I want to transform to

'here is my_text to replace and some_more'

i.e. wherever there are double square brackets, remove them and replace spaces in the contents with underscores.

My attempt to do that is the regex

select regexp_replace(
'here is [[my text]] to replace and [[some more]]',
E'\\[\\[(.*?)\\]\\]',
replace(E'\\1', ' ', '_'),
'g'
);

which results in

'here is my text to replace and some more'

It half works, i.e. it removes the brackets but doesn't seem to process the inner replace. It's as if the select were just

select regexp_replace(
'here is [[my text]] to replace and [[some more]]',
E'\\[\\[(.*?)\\]\\]',
E'\\1',
'g'
);

I've a feeling I'm missing something fundamental, any idea what?

Thanks
Oliver


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux