Postgres | Function to remove HTML tags from text

Author - Kailash Kumar
18.12.2017
|
0 Comments
|

Problem: How to create a function in Postgres that will remove HTML tags from a piece of text?

Solution: Create function in Postgres :

CREATE OR REPLACE FUNCTION strip_tags(TEXT) RETURNS TEXT AS $$
SELECT regexp_replace($1, ‘<[^>]*>’, ”, ‘g’)
$$ LANGUAGE SQL;

How to use:

SELECT strip_tags('<div>Kailash</div><b>Kumar</b>');

Output: KailashKumar

Note: This function will remove all the content between < and > symbol. If HTML tags are not proper then your text may also get removed so check your HTML before parsing it through this function.

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *

Send your message