Skip to content

Instantly share code, notes, and snippets.

@jianhe-fun
Created April 4, 2023 06:31
Show Gist options
  • Save jianhe-fun/d4afee9bc4d485a253c129df38e8632d to your computer and use it in GitHub Desktop.
Save jianhe-fun/d4afee9bc4d485a253c129df38e8632d to your computer and use it in GitHub Desktop.
escape_regular_expression.sql
/*
https://stackoverflow.com/questions/5144036/escape-function-for-regular-expression-or-like-patterns/45741630#45741630
escape regular expression.
*/
CREATE OR REPLACE FUNCTION public.f_regexp_escape(text)
RETURNS text
LANGUAGE sql
IMMUTABLE PARALLEL SAFE STRICT
AS $function$
select regexp_replace($1,'([!$()*+.:<=>?[\\\]^{|}-])','\\\1','g')
$function$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment