Saturday, 08 September 2012 19:51

Useful Tip: Regular expression to find HTML Attributes

Written by
Rate this item
(1 Vote)

I use OpenOffice for my text editing. Its got some nice export features for *.pdf and *.html. In fact I produce my fact sheet and thought it would be nice to put it up here on too. However, when you export into *.xhtml you get all the class & id & style attributes and I don't want them!

So I thought:

What a great opportunity to practice my regular expressions!

Again, since I wanted to find all the 'class="SOMETHING"', 'id="SOMETHING"' and 'style="SOMETHING"' I needed a good match for "SOMETHING". After messing around for a little while I came up with this:


The first part (class|id|style) say's: match 'class' or 'id' or 'style', that's pretty easy.

The second part: ="[^"]+" is a little more confusing. It says match ="SOMETHING" where something has no quotation mark(s) in it [^"] is the SOMETHING.

Check out for more.
Read 17096 times Last modified on Tuesday, 15 January 2013 18:34

Cameron is a PHP Application Developer and consultant and spends much of his time furthering the business goals of his company Magnetic Merchandising Inc. which he started in 2005.

Cameron has provided technical deployment and consultation for many entities since starting MMI. Much of that work has been in complex hosted auction platforms, professional Joomla! deployments and extension development and sales.

As such, Cameron has acquired a deep technical skill-set, a sensitivity to client needs, and the ability to produce anything those clients can visualize.

Everyday, he actively seeks out and becomes familiar technologies that will give MMI clients maximum return for their web development and general e-presence dollar.