RosettaCodeData/Task/Determine-if-a-string-is-squeezable/DuckDB/determine-if-a-string-is-squeezable.duckdb
2025-08-11 18:05:26 -07:00

18 lines
919 B
Text

create or replace function Guillemets(s) as format('«««{}»»»', s);
create or replace function squeeze(str, c) as
regexp_replace(str, regexp_escape(c) || '+', c, 'g');
### Examples
create or replace table t(s,c) as values
('"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ', '-'),
('..1111111111111111111111111111111111111111111111111111111111111117777888', '7'),
('I never give ''em hell, I just tell the truth, and they think it''s hell. ', '.'),
(' --- Harry S Truman ', ' '),
(' --- Harry S Truman ', '-'),
( ' --- Harry S Truman ', 'r'),
('SabcSS:SSdefSSSghSS', 'S')
;
select length(s), c, Guillemets(squeezed) as "«««squeezed»»»", length(squeezed)
from (select s, c, squeeze(s,c) as squeezed from t);