Use the trim function if you can delete all trailing dashes or use regexp_replace if you need only the last dash. Trim probably works better than regexp_replace.
with strings as ( select 'sdfs-dfg4t-etze45z5z-' as string union all select 'sdfs-dfg4t-etze45z5z--' as string union all select 'gsdhfhsfh-rgertggh' ) select string, trim(trailing '-' from string) as all_trimmed, regexp_replace(string, '-$', '') as one_trimmed from strings
Result:
string all_trimmed one_trimmed sdfs-dfg4t-etze45z5z- sdfs-dfg4t-etze45z5z sdfs-dfg4t-etze45z5z sdfs-dfg4t-etze45z5z-- sdfs-dfg4t-etze45z5z sdfs-dfg4t-etze45z5z- gsdhfhsfh-rgertggh gsdhfhsfh-rgertggh gsdhfhsfh-rgertggh
Jeremy shimanek
source share