Created
August 2, 2024 12:25
-
-
Save Black-Milk/1a23bac33bef9c6303d4ada443e8b161 to your computer and use it in GitHub Desktop.
Postgres HTML Tag Remover
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION REMOVE_HTML_TAGS(TEXT) RETURNS TEXT AS | |
$$ | |
DECLARE | |
INPUT_TEXT ALIAS FOR $1; | |
CLEAN_TEXT TEXT; | |
BEGIN | |
-- Remove Tags (e.g. <p>, <a>, <div>) | |
CLEAN_TEXT := REGEXP_REPLACE(INPUT_TEXT, '<[^>]+>', '', 'g'); | |
-- Remove entities (e.g. ) | |
CLEAN_TEXT := REGEXP_REPLACE(CLEAN_TEXT, | |
'&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});', | |
'', 'g'); | |
RETURN CLEAN_TEXT; | |
END; | |
$$ LANGUAGE PLPGSQL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment