16 lines
502 B
Text
16 lines
502 B
Text
# `sep` can be a single character or a string but it will be interpreted
|
|
# as part of a regexp within square brackets, so be careful if characters
|
|
# such as `-` are used.
|
|
create or replace function remove_comment(s, sep) as (
|
|
regexp_replace(s, '\s*[' || sep || '].*', '')
|
|
);
|
|
|
|
# Examples
|
|
|
|
select s,
|
|
remove_comment(s, '#') as decommented,
|
|
regexp_replace(decommented, ' ', '_','g') as visible
|
|
from unnest(
|
|
['apples ; pears # and bananas',
|
|
'apples # pears ; and bananas']
|
|
) _s(s);
|