String postgresql manipulation?

Asked

Viewed 213 times

3

I’d like to manipulate a String with regexp_replace as follows:

String to manipulate:

'TESTE <<TESTE1>> TESTE <<TESTE2>>'

String after function:

'TESTE TESTE'

I tried it this way:

select regexp_replace('TESTE <<TESTE1>> TESTE <<TESTE2>>', '<<.*>>','')

but only returns the 'TESTE'.

1 answer

2


Use the regex:

<<.*?>>

You will marry everything that stands between the signs of << and >> (including the signs).

But also use the flag 'g' (global) to replace all occurrences (otherwise it will replace only the first):

select regexp_replace('TESTE <<TESTE1>> TESTE <<TESTE2>>', '<<.*?>>','','g')

Check on the Sqlfiddle

Browser other questions tagged

You are not signed in. Login or sign up in order to post.