Manipulation String postgresql?

3

I would 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 returns only 'TESTE' .

    
asked by anonymous 02.05.2018 / 16:33

1 answer

2

Use regex:

<<.*?>>

It will match everything between << and >> signs (including 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')

See in SQLFiddle

    
02.05.2018 / 16:49