Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove HTML Tags from a text using SQL

I have column in a table which contains HTML text(data contains HTML tags) and also normal text.

I need to remove the HTML tags in the data wherever it exists.

Steps I planned:

  1. Filter only the records which contains HTML tags. --> I am able to complete this step. My Logic: where HTMLStirng like('<%>%')
  2. Replace HTML tags with a blank space. --> I am trying to apply replace function. But I am not able to.

For Example:

<p>Paragraph</p>
<b>bold</b><I>Italic</I>
Normal Text

My Output shold be:

Paragraph
BoldItalic
Normal Text

Can someone help me in the step 2 ?

like image 376
Sree Bhanu Avatar asked Aug 03 '26 22:08

Sree Bhanu


1 Answers

If you are using Oracle, try the following

SELECT Regexp_replace(your_column_name, '<.+?>') 
FROM   dual;

Example

SELECT Regexp_replace('<b>bold</b><I>Italic</I> Testing', '<.+?>') 
FROM   dual;
like image 141
Jacob Avatar answered Aug 06 '26 15:08

Jacob