Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Modify HTML content saved in a DB table

Avatar of Jorge Maldonado
Jorge Maldonado asked on
HTMLC#Regular Expressions
9 Comments1 Solution146 ViewsLast Modified:
I have a table in a DB with a general text field which contains HTML formatted text. I need to parse the content of such a field, find all the "img" tags and perform 2 operations (only for "img" tags):

1) Remove completely the "style" attribute (if there is one).
2) Add a class="img-responsive" attribute.

For example, a simple string to be parse can be as follows:

<p>This is some text</p>
<img src="http://www.mywebsite.com/myImage.jpg" alt = "" style="width:600px; height: 400px;"/>

Or, something more complex:

<p style="margin: 0px 0px 10px; background: white; font-size: 14.6667px; font-family: Calibri, sans-serif;"><span style="font-size: 14pt; font-family: Georgia, serif; color: #404040;">
<img src="http://www.mywebsite.com/myImage.jpg" alt="" style="width:600px; height: 898px;" />
<br /></span></p>  

In both cases, the "img" tag should result in:

<img src="http://www.mywebsite.com/myImage.jpg" alt="" class="img-responsive" />

I know that one option is to use regular expressions but I do not have any experience with them. I will be using C# to perform this task.
I will very much appreciate your help.

Jorge Maldonado
Avatar of Jorge Maldonado
Jorge Maldonado

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answers