Monday, July 1, 2019

SQL QUERY TO REPLACE HTML TAGS FROM A STRING USING REGEXP_REPLACE


1.      Below query is used to eliminate html tags and other entities like &amp ,&nbsp etc. 

SELECT trim(regexp_replace('<p style="margin-left:30px;">Replacing html tags &amp; entities with space using regular expresion&nbsp;.</p>',
'<.+?>|\&(nbsp;)|(amp;)|(quot;)|(lt;)|(gt;)', ' ')) as plain_col
FROM dual ;

Result:

Replacing html tags & entities with space using regular expression.

2.    If you want to add new entity like font-size:xx-large; add the code in the above expression as shown below.


SELECT trim(regexp_replace(column_name,
'<.+?>|\&(nbsp;)|(amp;)|(quot;)|(lt;)|(gt;) |
(font-size:xx-large;)', ' ')) as plain_col
FROM Table_Name ;

3

No comments: