Matching consecutive digits REGEXP_REPLACE in Redshift
问题 I'm trying to remove consecutive numbers from a string in Redshift. From '16,16,16,3,3,4,16,16,' I want to get '16,3,4,16,' . The following construction doesn't work for me: SELECT regexp_replace('16,16,16,3,3,4,16,16,', '(.+)\1{1,}', '\1'); It's returning exactly the same string. :( Thanks! 回答1: Here is the answer using a Redshift python UDF. create or replace function dedupstring(InputStr varChar) returns varchar stable as $$ OutputStr='' PrevStr='' first=True for part in InputStr.split(','